Javascript - Undefined

1 - 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.

3 - Example

if (typeof sec === 'undefined') console.log("The variable sec is not defined");

4 - 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.

5 - Documentation / Reference

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap