Reputation: 917
All this is one expression. What exactly gets put inside div in the end? What's it called when you have a bunch of comma delimited expressions?
var div = document.createElement( "div" ),
documentElement = document.documentElement,
all,
a,
select,
opt,
input,
tds,
events,
eventName,
i,
isSupported;
Upvotes: 0
Views: 76
Reputation: 4509
This is just the definition of some variables. In JavaScript you can define and/or initialize variables without having to write the var
-statement for every variable like this.
var x=0, y=1, array=[], var1, var2;
So this is basically what is happening here.
Upvotes: 2
Reputation: 707326
It is just the declaration of a bunch of variables inside a function scope. The first two variables are also initialized with their declaration. You can declare/initialize multiple variables at once by separating each with a comma like is done here.
In other uses, the comma character is an operator in javascript. From MDN: The comma operator evaluates both of its operands (from left to right) and returns the value of the second operand.
The variable div
is initialized here to an empty div tag. There is nothing inside it yet until later code uses it. The code following this in jQuery, puts some content into that div and then runs a series of test operations on it to do feature tests and see what features are supported in the current browser.
Upvotes: 3
Reputation: 47099
To first answer:
var div = document.createElement( "div" ),
documentElement = document.documentElement,
all,
a,
select,
opt,
input,
tds,
events,
eventName,
i,
isSupported;
is the same as:
var div = document.createElement( "div" );
var documentElement = document.documentElement;
var all;
var a;
var select;
var opt;
var input;
var tds;
var events;
var eventName;
var i;
var isSupported;
Upvotes: 2
Reputation: 943564
What exactly gets put inside div in the end?
The return value of document.createElement( "div" )
.
What's it called when you have a bunch of comma delimited expressions?
The comma is just an operator. It returns the right hand side, but it has lower precedence that =
and noting to the left ever captures the value.
This is just a way of avoiding typing var
over, and over, and over…
Upvotes: 1
Reputation: 116110
It's called a series of variable declarations. It's just like writing:
var div = document.createElement( "div" );
var documentElement = document.documentElement;
var all;
var ...
So they are unrelated, the other variables have nothing to do with the div.
Upvotes: 1