Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

In below code, x is global. Since, var is not used to declare the variable, it is added to global scope. To make it local to function use var, let or const. See Why are global variables considered bad practice?Why are global variables considered bad practice?

Although a minor thing, but this could lead to unexpected results in some cases. I recommend to add semi-colons explicitly and not rely on automatic semicolon insertion. See What are the rules for JavaScript's automatic semicolon insertion (ASI)?What are the rules for JavaScript's automatic semicolon insertion (ASI)?

In below code, x is global. Since, var is not used to declare the variable, it is added to global scope. To make it local to function use var, let or const. See Why are global variables considered bad practice?

Although a minor thing, but this could lead to unexpected results in some cases. I recommend to add semi-colons explicitly and not rely on automatic semicolon insertion. See What are the rules for JavaScript's automatic semicolon insertion (ASI)?

In below code, x is global. Since, var is not used to declare the variable, it is added to global scope. To make it local to function use var, let or const. See Why are global variables considered bad practice?

Although a minor thing, but this could lead to unexpected results in some cases. I recommend to add semi-colons explicitly and not rely on automatic semicolon insertion. See What are the rules for JavaScript's automatic semicolon insertion (ASI)?

deleted 112 characters in body
Source Link
Tushar
  • 3k
  • 1
  • 21
  • 28

Here's screenshot for reference.

JSPerf Comparison

Here's screenshot for reference.

JSPerf Comparison

deleted 11 characters in body
Source Link
Tushar
  • 3k
  • 1
  • 21
  • 28

enter image description hereJSPerf Comparison

enter image description here

JSPerf Comparison

added 124 characters in body
Source Link
Tushar
  • 3k
  • 1
  • 21
  • 28
Loading
Source Link
Tushar
  • 3k
  • 1
  • 21
  • 28
Loading