4
\$\begingroup\$

I keep coming across JavaScript solutions that use the print() function as if it behaved like console.log(). (Random example here ).

I'm confused by this. In Firefox and Chrome, calling print() pops up a print dialog, and otherwise produces no output. In NodeJS, print is not defined.

So I don't really understand the basis for claiming that a program that uses print() behaves correctly.

The only place I can see that print() behaves like this is...in Try It Online, in either "JavaScript (V8)" or "JavaScript (SpiderMonkey)".

What am I missing? MDN says it's "newly available" in Baseline 2023, so did print() previously do something completely different from this?

I mean, I guess it's fine to say "my solution is written in TIO's specific dialect of JavaScript", just like any other language is acceptable, but perhaps it should be more specifically flagged as such.

\$\endgroup\$
4
  • 4
    \$\begingroup\$ Different implementations of JavaScript exist, and languages on CGCC are defined by their implemenation. In most browser JavaScript, print opens a print dialogue, in node.js it is undefined, and in spidermonkey / V8 it prints to the console. Each one of these is a different JavaScript implemenation, with its own advantages and disadvantages, and answers are free to use whichever they feel fit. Different implementations are considered different languages, and as such aren't considered to be competing with each other. \$\endgroup\$ Commented Apr 3 at 3:08
  • 1
    \$\begingroup\$ Your linked example already flags the answer possibly being specific to the V8 implementation, is that not good enough? \$\endgroup\$ Commented Apr 3 at 7:48
  • \$\begingroup\$ Well I guess my confusion is that the link that TIO generates for v8 goes to a page that says V8 is used in NodeJS and Chrome. But the print function works in neither. So it's not really V8, it seems to be very TIO specific. \$\endgroup\$ Commented Apr 3 at 10:57
  • \$\begingroup\$ I guess my gripe is with TIO and the execution environment it provides not matching actual browser environments. \$\endgroup\$ Commented Apr 3 at 11:01

1 Answer 1

3
\$\begingroup\$

Languages are defined by Implementation

Our community consensus is that Language is defined by Implementation. As such, because there is an implementation in which this is valid then that implementation is valid.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.