Javascript
Variables, Operators and Construct
JavaScript variables are containers for storing data
values.
JavaScript uses reserved keyword var to declare a
variable. A variable must have a unique name. You
can assign a value to a variable using equal to (=)
operator when you declare it or before using it.
Syntax:
var <variable-name>;
var <variable-name> = <value>;
Example: Variable Declaration & Initialization
var one = 1; // variable stores numeric value
var two = 'two'; // variable stores string value
var three; // declared a variable without
assigning a value
Arithmetic Operators
Arithmetic operators are used to perform arithmetic
on numbers:
Assignment Operators
Assignment operators assign values to JavaScript
variables.
String Operators
The + operator can also be used to add (concatenate)
strings.
Comparison Operators
Constructs
Construct is a generic term referring to an arbitrary
aggregate of code in a specific formation. It is not a
javascript-specific term.
Basically, it can apply to anything. So, while the code
you referenced is a construct known as a self
invoking anonymous function, var x = "hello world";
is a construct known as a variable declaration and
assignment.
Example
function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}
Arrays
JavaScript arrays are used to store multiple values in
a single variable.
An array is a special variable, which can hold more
than one value at a time.
Example:
var guitars = [“Fender”, ”Gibson”, ”Ibanez”];
Syntax:
var array_name = [item1, item2, ...];
Output