Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Null vs Undefined | Data Types and Variables
Introduction to JavaScript (staging)
course content

Conteúdo do Curso

Introduction to JavaScript (staging)

Introduction to JavaScript (staging)

1. Introduction
2. JavaScript syntax
3. Data Types and Variables

Null vs Undefined

Similarities Between <code class="go3679463865">null</code> and <code class="go3679463865">undefined</code>

  • Both are Falsy:
    A falsy (sometimes written falsey) value is a value that is considered as false when encountered in a Boolean context. There are six-falsy-value in JavaScript.
    • NaN (Not A Number)
    • 0 (Zero)
    • null
    • undefined
    • '' (empty string)
    • false
      Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
  • Both are Primitive Values:
    JavaScript has seven primitive values including null and undefined. Here is a full list:
    • Null
    • Undefined
    • String
    • Number
    • BigInt
    • Symbol
    • Boolean

<code class="go3679463865">null</code> !== <code class="go3679463865">undefined</code>:

Although null and undefined share some similarities but they are different from each other and it is obvious that the null and undefined are not strictly equal.

1
console.log(null === undefined);
copy

But null loosely equals undefined.

1
console.log(null == undefined)
copy

As we talk in the previous chapter == checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But === does not perform type type coercion.

Summary:

  • The undefined variables are those variables that are declared without any values assigned to them.
  • null is not assigned to a variable by default like the undefined.
  • Both the null and undefined are falsy values.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 3. Capítulo 32
toggle bottom row

Null vs Undefined

Similarities Between <code class="go3679463865">null</code> and <code class="go3679463865">undefined</code>

  • Both are Falsy:
    A falsy (sometimes written falsey) value is a value that is considered as false when encountered in a Boolean context. There are six-falsy-value in JavaScript.
    • NaN (Not A Number)
    • 0 (Zero)
    • null
    • undefined
    • '' (empty string)
    • false
      Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
  • Both are Primitive Values:
    JavaScript has seven primitive values including null and undefined. Here is a full list:
    • Null
    • Undefined
    • String
    • Number
    • BigInt
    • Symbol
    • Boolean

<code class="go3679463865">null</code> !== <code class="go3679463865">undefined</code>:

Although null and undefined share some similarities but they are different from each other and it is obvious that the null and undefined are not strictly equal.

1
console.log(null === undefined);
copy

But null loosely equals undefined.

1
console.log(null == undefined)
copy

As we talk in the previous chapter == checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But === does not perform type type coercion.

Summary:

  • The undefined variables are those variables that are declared without any values assigned to them.
  • null is not assigned to a variable by default like the undefined.
  • Both the null and undefined are falsy values.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Seção 3. Capítulo 32
toggle bottom row

Null vs Undefined

Similarities Between <code class="go3679463865">null</code> and <code class="go3679463865">undefined</code>

  • Both are Falsy:
    A falsy (sometimes written falsey) value is a value that is considered as false when encountered in a Boolean context. There are six-falsy-value in JavaScript.
    • NaN (Not A Number)
    • 0 (Zero)
    • null
    • undefined
    • '' (empty string)
    • false
      Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
  • Both are Primitive Values:
    JavaScript has seven primitive values including null and undefined. Here is a full list:
    • Null
    • Undefined
    • String
    • Number
    • BigInt
    • Symbol
    • Boolean

<code class="go3679463865">null</code> !== <code class="go3679463865">undefined</code>:

Although null and undefined share some similarities but they are different from each other and it is obvious that the null and undefined are not strictly equal.

1
console.log(null === undefined);
copy

But null loosely equals undefined.

1
console.log(null == undefined)
copy

As we talk in the previous chapter == checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But === does not perform type type coercion.

Summary:

  • The undefined variables are those variables that are declared without any values assigned to them.
  • null is not assigned to a variable by default like the undefined.
  • Both the null and undefined are falsy values.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo

Tudo estava claro?

Similarities Between <code class="go3679463865">null</code> and <code class="go3679463865">undefined</code>

  • Both are Falsy:
    A falsy (sometimes written falsey) value is a value that is considered as false when encountered in a Boolean context. There are six-falsy-value in JavaScript.
    • NaN (Not A Number)
    • 0 (Zero)
    • null
    • undefined
    • '' (empty string)
    • false
      Any value other than the above six falsy values, in JavaScript, will be considered as truthy.
  • Both are Primitive Values:
    JavaScript has seven primitive values including null and undefined. Here is a full list:
    • Null
    • Undefined
    • String
    • Number
    • BigInt
    • Symbol
    • Boolean

<code class="go3679463865">null</code> !== <code class="go3679463865">undefined</code>:

Although null and undefined share some similarities but they are different from each other and it is obvious that the null and undefined are not strictly equal.

1
console.log(null === undefined);
copy

But null loosely equals undefined.

1
console.log(null == undefined)
copy

As we talk in the previous chapter == checks the loose equality. But In JavaScript, a double equals tests for loose equality and it performs type coercion. type coercion means converting the value to the common type. But === does not perform type type coercion.

Summary:

  • The undefined variables are those variables that are declared without any values assigned to them.
  • null is not assigned to a variable by default like the undefined.
  • Both the null and undefined are falsy values.

Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 3. Capítulo 32
Mude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt