How do I output something in Rhino?

Bentley4 picture Bentley4 · Apr 4, 2012 · Viewed 12.6k times · Source

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.

Answer

Quentin picture Quentin · Apr 4, 2012

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");