+ 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??

17th Nov 2019, 10:31 AM
Sumit Sinha
Sumit Sinha - avatar
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.
17th Nov 2019, 10:36 AM
Russ
Russ - avatar
+ 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
17th Nov 2019, 11:26 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar