Understanding the “undefined” variable in Javascript

There’s usually a lot of misunderstanding surrounding the undefined variable so I am going to attempt to demystify it by sharing some knowledge around this.

When javascript values are undeclared they have an initial value of undefined e.g

var myVar; -has a value of undefined

If you do a mathematical operation on an undefined variable you will get a NaN i.e Not a Number

If you concatenate a string with an undefined variable you will get a literal string of undefined.

--

--

George Mwaura Karumbi

Cybersecurit Specialist/Software Engineer based in Nairobi Kenya.