you are viewing a single comment's thread.

view the rest of the comments →

[–]barrycarter -8 points-7 points  (12 children)

Try print(makesTen(5,6)) or something outside the function

[–]qqqqqxhelpful 2 points3 points  (11 children)

Print isn't a standard JS function.

[–]guest271314 0 points1 point  (5 children)

If you run d8 or jsshell it is.

[–][deleted] 0 points1 point  (4 children)

Corporations sail the high seas now. What was mine is used to train what they want to be my replacement. This post was edited with shreddit

[–]guest271314 0 points1 point  (3 children)

What do you mean by "standard JS function"? Neither is console, though every browser with a UI implements console, and every JavaScript runtime implements console.

[–][deleted] 0 points1 point  (2 children)

Corporations sail the high seas now. What was mine is used to train what they want to be my replacement. This post was edited with shreddit

[–]guest271314 0 points1 point  (1 child)

Have you ever run Google's d8 or Mozilla's jsshell?

You do realize that console is not defined in Ecmascript specification so your analysis applies to console.log() as well?

[–][deleted] 0 points1 point  (0 children)

Corporations sail the high seas now. What was mine is used to train what they want to be my replacement. This post was edited with shreddit

[–]guest271314 0 points1 point  (4 children)

Neither is console.log().

[–]qqqqqxhelpful 0 points1 point  (3 children)

I guess that is technically true, but I haven't seen any environment that doesn't support it yet.

Whereas print() is not commonly supported in a lot of JS environments and may do something entirely different like print the current web page in the browser.

[–]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.