! operator in JavaScript

03WYchadwick

New Member
I am now confused about ! operator in JavaScript. My understanding was ! operator operates only on boolean. But a comment to one of my answers says it can operate on anything and returns a boolean, which happened to be true after I did some tests.\[code\]alert(!undefined); //truealert(!function(){}); //falsealert(!{}); //falsealert(!null); //truealert(!()); //crashalert(!"false"); //falsealert(!false)?;???????????? //true??????????????????\[/code\]Can somebody help me generalize the behavior of ! operator.EDITEven more confusing stuff:\[code\]?alert( new String() == ""); //truealert(!""); //truealert(! new String()); //false\[/code\]How??
 
Top