I'm looking for the javascript equivalent of Python2.x's print "hi"
.
I'm working with the Rhino javascript interpreter in the ubuntu terminal.
When I type:
document.write{"hi"}
I get the error that 'document' is not defined.
I'm looking for the javascript equivalent of Python2.x's print "hi"
.
I'm working with the Rhino javascript interpreter in the ubuntu terminal.
When I type:
document.write{"hi"}
I get the error that 'document' is not defined.
JavaScript doesn't have any built in methods to provide output. Scripts have to depend on features provided by the host environment for that.
document
is an object that is available in web browsers, but not in Rhino. Even if it was available, document.write
is a function. You use ()
to call a function, not {}
.
Rhino provides a print
function.
print("hi");
I don't think you have access to the 'document' object - as the one I think you're referring to is only available when javascript is run in the browser.
Also, use normal brackets rather than curly brackets to invoke functions.
Just try:
print('Hello, world!')
© 2022 - 2024 — McMap. All rights reserved.
node myfile.js
. If you want to print in a node script just useconsole.log
like in the browser. – Urumchi