javascriptの中で作業するとき、誰かが私に平等/不等式と型変換をテストする上で良いリファレンスまたは説明を提供できますか?JavaScriptの平等
私はeqeq(==)とeqeqeq(===)の使用について2つの考え方があるのを見ていますが、eqeqを使用しないでください使用するのがより安全です。
私はいくつかの基本的なサンプルで遊んでてきたと私はトラブル差や時に最高の他の上のいずれかを使用する目の肥えを持っています:
例えば:ここで私は書いていたいくつかの基本的なスクリプトです。 eqeqまたはeqeqeqを使ってテストすると、同じ結果が得られます。私は別の結果を得る例をまだ見ていません(つまり、eqeqを使用するとeqeqeqがfalseを返すtrueを返します)。
function write(message){
document.getElementById('message').innerHTML += message +'<br/>';
}
var tim = { name: "tim" };
var tim2 = { name: "tim" };
//objects are equal to themselves (== vs ==== eqeq or eqeqeq)
write("tim eq tim: " + (tim == tim)); //returns true
//objects are only equal to themselves regardless of containing value got that
write("tim eq tim2: " + (tim === tim2)); //returns false
//access the primative type to test true or false
write("tim value eq tim2 value: " + (tim.name === tim2.name)); //returns true
//how does this differ in efficency over the eqeq operator? is one safer to use over the other?
//write("tim value eq tim2 value: " + (tim.name == tim2.name)); //also returns true
//testing primatives
write("apple eqeqeq apple: " + ("apple" === "apple")); //true
write("apple eqeqeq apple: " + ("apple" == "apple")); //true
誰かが私が読むことができる説明や参照を提供できますか?
歓声、
http://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use –