DEV Community

Abhishek Gupta for Coder Studios

Posted on • Edited on

1

Difference between null, undefined and not defined in javascript

What is "undefined"?

  • In JavaScript, "undefined" is a primitive value automatically assigned to variables that have been declared but have not been initialized with a value. It also represents the value returned by functions that do not explicitly return anything. Essentially, it denotes the absence of a meaningful value.

Example


let x;
console.log(x); // Output: undefined

function doSomething() {
    // Kuch bhi return nahi kiya gaya
}
console.log(doSomething()); // Output: undefined


Enter fullscreen mode Exit fullscreen mode

Not defined

  • In JavaScript Not Defined is a ReferenceError that occurs when you try to use a variable, function, or object property that has not been declared or created in your code. This error is often caused by typographical mistakes or using the wrong variable name.

console.log(a); 
var a = 5; 
console.log(a); 
console.log(b);  //  // ReferenceError: b is not defined


Enter fullscreen mode Exit fullscreen mode

What is null in JavaScript?

  • In JavaScript, null is a special value that represents an empty or unknown value. It is often used to indicate that a variable or object property has no value or is explicitly empty. Unlike undefined, null is a deliberate assignment to a variable to indicate that it has no value.

Link

Join Discord :- https://github.com/Coder-Studies
Follow Us of Github :- https://github.com/Coder-Studies

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (3)

Collapse
 
techifydev profile image
Abduqudus

Informative !!!

Collapse
 
abhishek_gupta_f080622fe3 profile image
Abhishek Gupta

Join Our Discord Community . To Stay Updated discord.gg/b44tgZGz

Collapse
 
abhishek_gupta_f080622fe3 profile image
Abhishek Gupta

Thanks

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

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay