2

Most blogs say that undefined type is a state of allocated on memory but not having any value and null type is a state of allocated on memory having a null value.

however I think in case of a.js file.

a.js includes console.log(typeof tmp);

and It may print undefined. but In a.js file, var tmp is not declared. so I guess tmp variable is not allocated on memory but It is showed as undefined.

why does that??

SeongUk Mun
  • 213
  • 3
  • 8

1 Answers1

3

undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object. Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.

reference: http://www.ajaymatharu.com/javascript-difference-between-undefined-and-null/