+ 1
Why js is not giving error message
here in js console, I used a = 42; b=85; console.log(a+b); then output is 127 but here in variables a and b, I am not using var, let or const but still, it's not throwing an error? why??
3 Antworten
+ 2
By declaring variables without using 'let', 'var' etc. you are still declaring them, but as global variables. This is not disallowed in JS (hence no error) but highly unadvised.
+ 2
This is not allowed in "strict mode"
Use "strict mode" string in beginning of your script or inside the function, if you want to get error messages for such cases.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode