Search⌘ K
AI Features

Discussion: Oo Na Na Na

Explore how JavaScript treats the special NaN value and constant variables declared without initialization. Understand why NaN is not equal to anything, including itself, and learn to use the isNaN() function for accurate checks. This lesson enhances your grasp of JavaScript's unique behavior with undefined and invalid numeric operations.

Verifying the output

Now, it's time to execute the code and observe the output.

Javascript (babel-node-es2024)
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 result of an invalid or undefined mathematical operation. We may ...