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