jQuery.each(player, function(key, val){
if (el = $("#pr_attr_plain_"+key)){
el.text(val === "" ? 0 : " " + val);
}
});
I inherited a project and I came across something strange. The guy who started the project is an expereinced programmer, definitely more so then myself. Is there any value or reason (no matter how bad) in doing this:
if (el = $("#pr_attr_plain_"+key))
It works now and it's in a portion of the code that I don't have to touch. I don't want to change it and have it produce unexpected consequences without knowing what it might do.
Single Equal (=) in JavaScript We use Single Equal sign to assign value to the variable or to initialize an object. For example. var t = new Date(); //Variable assignment var amount = 100; //Object initialization var t = new Date();
Two equals signs placed together ask if two values are equal to each other. For example, the statement (A == B) is true when a is equal to b. An exclamation point and an equals sign placed together determine if two values are not equal to each other.
Triple equal sign in javascript means equality without type coercion. For example: 1=="1" // true, automatic type coersion 1==="1" // false, not the same type.
The equality operator ( == ) checks whether its two operands are equal, returning a Boolean result. Unlike the strict equality operator, it attempts to convert and compare operands that are of different types.
It can be correct. The code is equivalent to:
jQuery.each(player, function(key, val){
el = $("#pr_attr_plain_"+key);
if (el){
el.text(val === "" ? 0 : " " + val);
}
});
If the el = $("#pr_attr_plain_"+key)
evaluates to 0
or false
or null
or undefined
, it won't go inside the if-block. In all other cases it will.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With