NaN and isNaN Operator

Video

JavaScript Notes

JavaScript
    // NaN and isNaN ( )
    // NaN is a property of the global object
    // it represents a value which is Not a Number
    // it will be unequal !== to ANYTHING inside if ( )
    //
    // isNaN( ) first converts the value to a Number
    // next the coerced number is tested for NaN
    
    let log = console.log;
    let t = isNaN(true);     		// 1 …returns false
    let f = isNaN(false);			// 0 …returns false
    let n = isNaN(null);			// 0 …returns false
    let u = isNaN(undefined);		// NaN …returns true
    let b = isNaN(23);			    // 23 …returns false
    let c = isNaN('45');			// 45 …returns false
    let d = isNaN(new Date( ));		// timestamp …returns false
    let e = isNaN(' ');			    // 0 …returns false	
    let f = isNaN('    ');			// 0 …returns false
    let g = isNaN(new Date('28 August, 2017')); 	// Date String / NaN …returns true
    
    let a = Number(true);			// the variable is first cast as a number, then tested by isNaN
    log(a);					        // returns 1