Home > Web Front-end > JS Tutorial > What are the Falsey Values in JavaScript?

What are the Falsey Values in JavaScript?

Patricia Arquette
Release: 2024-12-29 08:38:11
Original
302 people have browsed it

What are the Falsey Values in JavaScript?

Falsey Values in JavaScript

In JavaScript, "falsey" values are those that evaluate to false in expressions such as if(value), value ? and !value.

List of Falsey Values

  • false
  • Zero of Number type: 0, -0, 0.0, 0x0
  • Zero of BigInt type: 0n, 0x0n
  • Strings of length 0: "", '', ``
  • null
  • undefined
  • NaN
  • document.all (in HTML browsers only)

What is "Falsey"?

"Falsey" simply means that JavaScript's ToBoolean function returns false for that value. ToBoolean underlies expressions like !value, value ? ... : ..., and if (value).

According to the official ECMAScript specification, the following rules apply to ToBoolean:

Argument type Result
Undefined Return false
Null Return false
Boolean Return argument
Number If argument is 0, -0, or NaN, return false; otherwise, return true
String If argument is an empty string (length 0), return false; otherwise, return true
BigInt If argument is 0n, return false; otherwise, return true
Symbol Return true
Object Return true

The above is the detailed content of What are the Falsey Values in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template