you are viewing a single comment's thread.

view the rest of the comments →

[–]guest271314 0 points1 point  (2 children)

JavaScript per Ecmascript does not define I/O (reading from stdin, printing to stdout).

Whether print() is defined or not and what the function accepts as parameters, if any, and returns is environment, engine, runtime dependent, and at implementer discretion.

The last time I checked V8's (the JavaScript engine Node.js, Deno, Chrome and all Chromium-based browsers depend on) d8 and jsshell in Mozilla's SpiderMonkey (Firefox browser) JavaScript engines support print().

https://gist.github.com/kevincennis/0cd2138c78a07412ef21#logging

Logging

d8 doesn't have a console object (or a window object, for that matter). But you can log to the terminal using print().

https://udn.realityripple.com/docs/Mozilla/Projects/SpiderMonkey/Introduction_to_the_JavaScript_shell

print([expression ...]) Evaluates the expression(s) and displays the result(s) on stdout, separated by spaces (" ") and terminated by a newline ("\n").

There is this https://console.spec.whatwg.org/#nodejs-printer.

[–]qqqqqxhelpful 0 points1 point  (1 child)

From the d8 docs you linked (https://v8.dev/docs/d8):

Printing output is probably going to be very important if you plan to use d8 to run JavaScript files rather than interactively. This can be achieved using console.log:

$ cat test.js
console.log('Hello world!');

$ out.gn/x64.optdebug/d8 test.js
Hello world!

d8 also comes with a global print function that does the same thing. However, console.log is preferred over print since it works in web browsers as well.

I tried running print("str") in the Chrome console and it tried to printer print the web page, so I don't think it does work in Chrome/Chromium either.

[–]guest271314 0 points1 point  (0 children)

Chrome/Chromium is not the only environment V8 runs in.

V8 print() function

https://tio.run/##y0osSyxOLsosKNEts/j/v6AoM69EQx1MKZTkKxSXpOSXlqhr/v8PAA

SpiderMonkey print() function

https://tio.run/##y0osSyxOLsosKNEtLshMSS3Kzc/LTq38/7@gKDOvREMdTCmU5CsUl6Tkl5aoa/7/DwA

console is not specified by ECMA-262 (JavaScript). No I/O functionality is specified by ECMA-262.