Discussion: Oo Na Na Na
Execute the code to understand the output and gain insights into encountering NaN values in JavaScript.
We'll cover the following...
Verifying the output
Now, it's time to execute the code and observe the output.
Press + to interact
let price = 10;let tax;const sum = price + tax;console.log(sum);
Understanding the output
In this puzzle, the statement const tax;
declares a constant variable without assigning any value to it. So, the variable holds a default value of undefined
. When trying to add undefined
to the value of price
, the operation yields NaN
(Not-a-Number).
NaN
is a special value in JavaScript that represents the ...