DEV Community

Cover image for Undefined or not defined?
Utkarsh Yadav
Utkarsh Yadav

Posted on

3 2 1 1 1

Undefined or not defined?

Table of Content

  • What is Undefined in JavaScript?
  • What is 'defined` in JavaScript ?
  • Difference between the both.

Undefined

Undefined is simply a Placeholder that is initialise to every variable at the time of memory execution in Global Execution Context.

Example:


console.log(a); // undefined
var a = 7; // Assign value 7 to a
console.log(a); // Log --> 7 on Screen

Not Defined

This is like an error, occurs when the code is trying to access the variable that is never been there in memory.

is
var b = 7; // Assign value 7 to b
console.log(a); // not defined

Difference Between Undefined and Not Defined

In JavaScript, they both are related to memory space and there is a very simple difference between them. If the variable name which is being accessed doesn’t exist in memory space then it would be not defined, and if exists in memory space but hasn’t been assigned any value till now, then it would be undefined.

So, Hope you got to know the simple difference between the two Jargons.

Don't stop learning, Keep exploring and learning.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series đź“ş

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series đź‘€

Watch the Youtube series

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay