Possible Duplicate:
null coalescing operator for javascript?
What does “options = options || {}” mean in Javascript?
Can someone explain me this expression? I stumbled accros the javascript line of code and I wondered what it means.
var node = element.node || element[element.length - 1].node;
node get's used like this below:
if (node.nextSibling) {
node.parentNode.insertBefore(this.node, node.nextSibling);
} else {
node.parentNode[appendChild](this.node);
}
At first i though node should be a boolean or something but it's not. Am I correct if i think that the meaning is: node is element.node but if the node attribute is undefined node is the last element in the array of element?
Your understanding is along the right lines; be aware that even if element.node
is defined, but is a falsey value (0
, false
etc.) that element[element.length - 1].node
will be assigned to node
instead.
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