From print() to console.log()
In this lesson, you ported the setup check’s lines to a JavaScript file, ran it with node, and
found out what happens to print()’s keyword arguments.
- Create a folder called
onboarding-checkin your home folder, save the port in it as a new file with the.jsextension,check-setup.js, and run it from that folder withnodeand its name, as you run a Python script withpython:node check-setup.js. Node runs the file from top to bottom. print()becomesconsole.log(). It puts a space between several values and prints strings without quotes, asprint()does.- Node’s
processobject holds the setup values, with no import:process.versions.node,process.platform, andprocess.cwd(). - JavaScript has no keyword arguments, so
sep=andend=don’t carry over. Give each line its ownconsole.log()instead. console.error()writes to stderr, likeprint(..., file=sys.stderr).- JavaScript has no
__name__, so a Python main guard doesn’t port. Keep the lines inside it.
Watch out for print() out of habit. JavaScript has no print() function, so the script stops
at that line with ReferenceError: print is not defined.
The team’s Python check prints its next steps with one print() and sep="\n":