1

I'm a beginner in JavaScript. I'm reading the book JavaScript: The Good Parts. On page 35, it has the code:

    ...
    walk_the_DOM(document.body, function (node) {
        var actual = node.nodeType === 1 && node.getAttribute(att);
        if (typeof actual === 'string' && (actual === value || typeof value !== 'string')) {
            results.push(node);
        }
});

I'm confuse about the value of the variable actual. Why is it a string type? Is it should be boolean type?

Frank
  • 1,215
  • 12
  • 24
  • 2
    The `&&` and `||` operators are a little "weird" in JavaScript. They don't return boolean values. Instead they return either the 1st or the 2nd argument. – gen_Eric Nov 07 '16 at 20:32
  • 1
    `actual` can be the boolean false if `node.nodeType !== 1` – Oriol Nov 07 '16 at 20:34
  • I found the answer on page 16. I missed that sentence before. The && operator produces the value of its first operand if the first operand is falsy. Otherwise, it produces the value of the second operand. – Frank Nov 07 '16 at 21:00

0 Answers0