I installed node.js on Windows machine and opened command prompt. When I tried "Hello World" examples the only output I'm getting is three dots:
node hello.js
...
Am I doing anything wrong?
The three dots in JavaScript are the spread / rest operator. Spread operator. The spread syntax allows an expression to be expanded in places where multiple arguments are expected.
Rest operator. When used within the signature of a function, where the function's arguments should be, either replacing the arguments completely or alongside the function's arguments, the three dots are also called the rest operator.
When we see three dots (…) in the code, it's either rest parameters or the spread operator. There's an easy way to distinguish between them: When three dots (…) is at the end of function parameters, it's "rest parameters" and gathers the rest of the list of arguments into an array.
The three dots are known as the spread operator from Typescript (also from ES7). The spread operator return all elements of an array. Like you would write each element separately: let myArr = [1, 2, 3]; return [1, 2, 3]; //is the same as: return [...myArr];
"node hello.js" is not valid javascript, so node repl ( Read-Evaluate-Print Loop ) assumes that error is because you are entering multi line javascript and indicates this with '...'. To exit multi line mode just enter '.' command.
As mentioned in first comment, this is common confusion (starting node.exe and entering 'node hello.js' in repl) - read linked answer first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With