What is the difference between == and === in JavaScript? [duplicate]
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: Javascript === vs == : Does it matter which “equal” operator I use? When would JavaScript == make more sense than ===? What is the difference between below methods in comparing a string with undefined value. var x; if(x==undefined) { alert(x); } and if(x===undefined) { alert(x); } Why should i prefer second method in this case.. Please let me know advantages.. 回答1: == attempts to convert the values to the same