Return to Snippet

Revision: 4249
at November 13, 2007 18:26 by 1man


Initial Code
function operators(){
	//Use of in Operator
	var o = {x: 1, y: 2};//Create object
	var haveX = "x" in o;//true
	var haveY = "y" in o;//true
	var haveZ = "z" in o;//false
	var haveMethod = "toString" in o;//true (inherited property)
	console.log(haveX, haveY, haveZ, haveMethod);
	
	var a = [1, 2, 3];
	var check1 = a instanceof Array;//true
	var check2 = a instanceof Object;//true (array is an object)
	var check3 = a instanceof RegExp;//false
	console.log(check1, check2, check3);
	
	var d = new Date();
	var check1 = d instanceof Date;//true
	var check2 = d instanceof Object;//true
	var check3 = d instanceof Number;//false
	console.log(check1, check2, check3);
}

Initial URL


Initial Description
Basic usage of the in and instanceOf operators.

Initial Title
Basic Usage of the 'in' and 'instanceOf' Operators

Initial Tags
javascript

Initial Language
JavaScript