Search code examples
javascriptlinuxrhino

How do I output something in Rhino?


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.


Solution

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