Reputation: 93
I am learning javascript . And I noted that the instructor was making variables in two ways . first was (for example):
var name ="Any string here";
and second method was simply writing the variable name without writing var first :
name="Any string here";
And the result was same . So , is there any difference between these two ?. Which one is better to use ?
Upvotes: 0
Views: 53
Reputation: 1844
var
before variable
declaration. var
. strict mode
using variable without declaration will cause ExceptionUpvotes: 1
Reputation: 54593
Leaving out var
makes it a global variable, so if you have name
multiple places in the code, they'll overwrite each other.
Upvotes: 2