4 ms·
And semicolons are optional in JavaScript, makes it whitespace sensitive I suppose.
by askvictor 9y ago
And semicolons are optional in JavaScript, makes it whitespace sensitive I suppose.
- austincheney 9y agoYes and no. The language specification requires the use of semicolons. If a semicolon is not supplied the interpreter will insert it for you. That magical insertion step is referred to as ASI. I don't remember if ASI is mentioned in the spec (as I don't think it is), but at the very least it is a de facto standard as missing ASI breaks the web. As stupid as all that sounds... semicolons are actually required to terminate statements in JavaScript.
- askvictor 9y agoAnd yet somehow the web doesn't break when one programmer uses \r\n while another uses \n. What was your original point about line terminators in this context?
- austincheney 9y agoI suppose that goes to how the language defines line termination and whether that language is OS aware. JS is completely independent of its execution context. Python may achieve this as well, and if so, then I am wrong in my thoughts about Python. Here is how JavaScript does this: * https://www.ecma-international.org/ecma-262/#sec-source-text https://www.ecma-international.org/ecma-262/#sec-source-text * https://www.ecma-international.org/ecma-262/#sec-line-terminators https://www.ecma-international.org/ecma-262/#sec-line-termin... ASI is defined in the spec here: https://www.ecma-international.org/ecma-262/#sec-automatic-semicolon-insertion https://www.ecma-international.org/ecma-262/#sec-automatic-s...