steveosoule
11/22/2014 - 12:23 AM

JavaScript Variable Type Conversions

JavaScript Variable Type Conversions

// FROM: http://samuli.hakoniemi.net/10-small-things-you-may-not-know-about-javascript/

var myVar   = "3.14159",
	str     = ""+ myVar,//  to string
	int     = ~~myVar,  //  to integer
	float   = 1*myVar,  //  to float
	bool    = !!myVar,  //  to boolean - any string with length and any number except 0 are true
	array   = [myVar];  //  to array