Photos
Posts

What will be the output of the following #JavaScript code?

<p id="foo"></p>
<script>
var movieName = "Bloodshot";...
var movieName;
document.getElementById("foo").innerHTML = movieName;
</script>

-----------------------
a) Error
b) Undefined
c) Bloodshot
d) Garbage value

Comment the right answer with an explanation.

See More

#JavascriptTips #javascript #js
Assigning a default value In Javascript
--------

The boolean operators in JavaScript can return an operand, and not always a boolean result as in other languages.

...

The Logical OR operator (||) returns the value of its second operand if the first one is Falsy, otherwise, the value of the first operand is returned.

Example:
z = "x" || "y"; // results z = "x"
z = false || "y"; // results z = "y"

Falsy values are those who coerce to false when used in a boolean context, and they are 0, null, undefined, an empty string, NaN and of course false.

See More