Javascript - Undefined
Table of Contents
About
When the value of variable or property is not defined, it gets the type undefined.
It's handy to see if a variable is passed as an argument of a function.
Are undefined:
- a not declared variable
- a declared variable without value
- functions that return no values
- the void operator.
Example
if (typeof sec === 'undefined') console.log("The variable sec is not defined");
Typescript
The question mark permits to manage an undefined object.
For instance, if location is undefined, you can write:
country = location?.getCountry()
country will then be undefined.