Open In App

What is Undefined X 1 in JavaScript ?

Last Updated : 18 Jan, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

JavaScript is one of the most popular lightweight, interpreted compiled programming languages. It is single-threaded and synchronous in nature. Scripts(program in JavaScript) re executed as plain text. They can be either written directly on our page or in an external JavaScript file. JavaScript can execute on any device that has a program called the JavaScript Engine, be it Browser. JavaScript is used for both client and server-side developments.

What is Undefined X 1 In Javascript?

We have to find out what is the result of Undefined X 1 in JavaScript , but before looking at the result we must know about Undefined in JavaScript. Undefined is a keyword in JavaScript that is related to memory space. Everything in JS which gets a space in memory is assigned Undefined until the memory space is initialized. Now Undefined X 1 in JavaScript yields NaN(Not a Number) as result. 

What is NaN in Javascript?

NaN in JavaScript stands for Not a Number that represents a non-writable property, a value which is not a number. It is rarely used in program but using NaN we can check whether entered number is a valid number or not. 

Let’s understand Undefined X 1 with the help of the following examples.

Example 1:  In this example, we are initializing a with undefined, then multiplying a with 1 to see the result of Undefined X 1.

Javascript




<script>
    var a = undefined;
    console.log(a * 1);
</script>


Output :

NaN

Explanation: The above example is an Indeterminate form operation, we are multiplying 1 with undefined, undefined being a keyword is not a valid number(value is not even initialized). Now multiplying it with some number will result in NaN.

Example 2: In this example, we are trying to parse a string to an integer, it will result in NaN.

Javascript




<script>
    console.log(parseInt("GeeksforGeeks"));
</script>


Output:

NaN

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads