N
N
NZ012020-12-15 14:38:51
Node.js
NZ01, 2020-12-15 14:38:51

Why does it return NaN instead of text file content?

Hello, instead of the contents of the article.txt file, it gives NaN

var fs = require('fs');

var myReadShort = fs.createReadStream(__dirname + '/article.txt');

myReadShort.on('data', function(chunk) {
    console.log("Новые данные получены:\n", + chunk);
});

I checked that the file exists, the name is that, but in the end it still gives out:
Новые данные получены:
 NaN

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Polos, 2020-12-15
@NZ01

You write a log to the console: string, COMMA, +chunk, it turns out that strings and a chunk with a unary plus are displayed, which leads it to a number, and as a result - NaN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question