Javascript

Special Characters

\' Single quote (‘)
\" Double quote (“)
\\ Backslash (\)
\b Backspace
\t Horizontal tab
\n New line character
\r Carriage return character
\f Form feed character
\ddd Octal sequence (3 digits)
\xdd Hexadecimal sequence (2 hex digits)
\udddd Unicode sequence (4 hex digits)
Two ways to create objects
var myCar = new Object();
var myCar2 = { };


Object Properties
var myCar = new Object();
myCar.make = 'Ford';
myCar.model = 'Explorer';
var myCar2 = { make: "Ford", model: "Explorer" };

Object Properties as Associative Arrays
var myCar = new Object();
myCar.make = 'Ford';
myCar["model"] = 'Explorer';
alert (myCar.make === myCar["make"]); // alerts true.



Because objects store their properties in an associative array, we can iterate over the properties using a for...in loop.
var myCar = new Object();
myCar.make = 'Ford';
myCar["model"] = 'Explorer';
myCar.year = 2003;
myCar.mileage = 60000;

var propValues;
for (var propName in myCar) {
propValues = propValues + " " + myCar[propName];
}
alert (propValues); / alerts "Ford Explorer 2003 60000 ";
var myOtherCar = {
make: "Ford",
model: "Explorer",
year: 2003,
mileage: 60000
print: function() {
alert (this.make + " " + this.model);
}
}

myOtherCar.print // alerts 'Ford Explorer'

//to remove..
myCar.print = null;
// to really delete
delete myCar.print;

var x = new Number();
if (x.constructor === Number) {
alert ("x is a number!");
}
The constructor property is key to mimicking a classic object-oriented system