Difference between undefined and null

Asked by: alf93
Date:
Viewed: 212
Answers: 1
  • 0

Hi,

Can someone explain to me what the difference is between undefined and null?

Thanks

Answers

Answer by: ChristianKovats

Answered on: 23 Mar 2023

  • 0

NULL is a special value which represents nothing or empty. You can initially set a variable to NULL. For example:

let fname = null;

Maybe we don’t know the name yet. Later we can change it.

fname = "John";

The variable below is undefined:

let age;

it is undefined because a value hasn’t been assigned to it yet.

Null is an assignment value, it is assigned to a variable, as seen above.

We have an article about Javascript data types, check it out.

 

Please log in to post an answer!