JavaScript undefined

JavaScript undefined is a primitive datatype which has only one value undefined.

If a variable is only declared but not initialized, then the variable holds the value undefined.

Variables Declared but Not Defined

In the following example, we declare a variable x, but do not define it. We shall display the value in x in a pre HTML Element.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
<body>
    <pre id="output"></pre>
    <script>
        var x;
        document.getElementById('output').innerHTML += x;
    </script>
</body>
</html>

Conclusion

In this JavaScript Tutorial, we learned what an undefined value is in JavaScript.