Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Working with null in JavaScript | Variables and Data Types in JavaScript
Introduction to JavaScript
course content

Conteúdo do Curso

Introduction to JavaScript

Introduction to JavaScript

1. JavaScript Fundamentals
2. Variables and Data Types in JavaScript
3. Performing Operations in JavaScript
4. Controlling Program Flow with Conditional Statements
5. Looping Through Data in JavaScript
6. Functions in JavaScript

book
Working with null in JavaScript

In JavaScript, the null type represents "nothing" or the absence of data. It is used to indicate that a variable intentionally lacks a value. The following example demonstrates that the null type produces no output in the console:

12345
let variable = null console.log("Some data 1") console.log(variable) console.log("Some data 2")
copy

The example above demonstrates that the null type produces no output in the console.

Note

  1. null is distinct from undefined;
  2. We use null when we need to signify the absence of data or to pass the concept of "nothing" to another part of the program.

For instance, imagine you're working on a game where you need to describe a hero's data. In some cases, the hero's name might be unknown or missing. If the variable containing the hero's name doesn't exist, attempting to access it would result in an error. Using the null type allows you to indicate that the hero has no name and can be passed to another part of the program.

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 2. Capítulo 5
We're sorry to hear that something went wrong. What happened?
some-alt