DEV Community

Ashlyn Joshy
Ashlyn Joshy

Posted on • Originally published at ashlynjoshy.hashnode.dev on

1

Undefined Vs Not Defined in Javascript

When working with JavaScript, you might run into the terms not defined and undefined. While they may sound identical, they represent different situations in JavaScript programming.

In phase one memory allocation, the Js will assign each variable a placeholder known as undefined.

To understand it better. Undefined occurs when memory is allocated for a variable but no values have been assigned yet.

If a variable is not even declared in the memory allocation and attempted to access, it is known as not defined.

console.log(x);
var x = 20;
console.log(x);
console.log(y);
Enter fullscreen mode Exit fullscreen mode

The output of the code will be

undefined
20
Uncaught ReferenceError: y is not defined

key points

not defined !== undefined

Never assign undefined to a variable manually.

So this was all about the Undefined and Not defined. Hope it helped you understand the concept better and make your journey of learning JavaScript better.

Thank you for reading the article 🙏🏻 and if you liked it, do share.

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs