JavaScript for Beginners

JavaScript Undefined

In JavaScript, a variable without a value, has the value undefined. The type is also undefined

 

Example :

 

​<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Operators</h1>
<h2>The typeof Operator</h2>
<p>The value (and the data type) of a variable with no value is <b>undefined</b>.</p>

<p id=”demo”></p>

<script>
let car;
document.getElementById(“demo”).innerHTML =
car + “<br>” + typeof car;
</script>

</body>
</html>

 

Output

JavaScript Operators

The type of Operator

The value (and the data type) of a variable with no value is undefined.

undefined
undefined

 

Description :

In JavaScript, undefined is a special value that means a variable has been declared but has not been assigned a value yet.