Problem:
the print is not working.
const print = console.log();
print("Hello World")
anyone have any ideas what is going on? I am trying to make a print function in JavaScript. I come from a Python environment… Please help me with this. I appreciate any help from someone who know how to solve this question. Thanks in advance.
Solution:
If you insist on doing it the wrong way, here’s what you can do:
const print = console.log
print("Hello World")
But the right way of doing it, is:
console.log("Hello World")
Some explanation: console.log
is a function, but console.log()
is the stuff that the function returns, which in this case, it’s undefined. So if you want to save a reference to the function, you should use console.log
.