Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

New to JavaScript, coming from Python, why is it not working?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading