by MatmaRex · 4y ago · 0 comments
Here is an example to illustrate:
console.log('a')
(1 < 2) ? console.log('b') : console.log('c')
You might expect this to output 'a', then 'b'. However, it instead outputs 'a' and then throws an error like this: Uncaught TypeError: console.log(...) is not a function
...because a semicolon was not inserted at the end of the first line. console.log = function(value){console.error(value);return function(value2){console.error(value2)}}
Your example runs just fine because there was never actually a syntaxError anywhere in it to begin with, let alone a sytanxError that could be fixed with a ; by ASI. Similarly if I define console.log = 2 all of the above will throw typeError but that also has nothing to do with ASI.This is precisely what "but if you need them to be separated in a special way you can add semicolons to manually control separation behavior" was referring to.