-1

Anyone please tell what is the difference between undefined and null in javascript and when I should use undefined and when null.

2

2 Answers 2

2

undefined means a variable has been declared but has not yet been assigned. null is an assignment value. It can be assigned to a variable as a representation of no value

example.

var a; alert(typeof(a)); var b = null; alert(typeof(b)); 

Running the above script will result in the following output:

undefined object

——————————-

Sign up to request clarification or add additional context in comments.

Comments

0

undefined is not defined at all... means, that given variable does not exist.

null is defined variable that has value set to null (so basically you can say that it is defined variable with undefined value)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.