Why can't I do this:
var fooElement, barElements; if(fooElement = document.getElementById('foo') && barElements = fooElement.getElementsByTagName('bar') && barElements[0] && barElements[0].onclick) { console.log(barElements[0].onclick); }
This won't work either:
var foo, bar; if(foo = true && bar = true) { console.log('yay'); }
Yes you can put assignment operator (=) inside if conditional statement(C/C++) and its boolean type will be always evaluated to true since it will generate side effect to variables inside in it.
multiple assignment A form of assignment statement in which the same value is given to two or more variables. For example, in Algol, a := b := c := 0. sets a, b, c to zero.
MultipleAssignment is a language property of being able to assign one value to more than one variables. It usually looks like the following: a = b = c = d = 0 // assigns all variables to 0.
Try this (it should give you a clue):
var foo, bar;
if((foo = true) && (bar = true))
{
console.log('yay');
}
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