Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

new

The new operator is used to create an instance of an object.

Syntaxvar obj = new Object( optional_parameters );

Examples

Create a new instance of an author-defined custom object. function ObjectClass( str, num ){ this.a = str; this.b = num } var obj = new ObjectClass( "cake", 7 ); alert( obj.a ); Creating new instances of some built-in objects. var str = new String( "Hello" ); var num = new Number( 5 ); var arr = new Array( "a","b","c" ); var today = new Date(); var bool = new Boolean( false );

JavaScript

Operators

deleteinstanceofnewthistypeofternaryvoid