When I fire up node.js in the terminal and run 4 + 4, it outputs 8 as expected. However, when I run the same code but from a file... I get no output unless I use console.log!?
- Why do I need console.log to output the result, when vanilla js should just do it basically?
- I thought
console.logwas code for the browser... Why is it running in node.js? Yes, I know that node.js is built on the same engine that chrome was built on... But still, they are two different products. Doesn'tconsole.logmake more sense on the browser side of things than node.js?
Much appreciated.
console.login javascript is just like theSystem.out.printlnin Java. It has got nothing to do with browser. The answer given by Fabiano is right.console.logis a syntax of javascript for logging something on to the terminal. In browsers the terminal is theconsole. That's all.