Home Web Front-end JS Tutorial Why does JavaScript have null? (Translation) - Tianbeiya

Why does JavaScript have null? (Translation) - Tianbeiya

Oct 06, 2017 am 10:42 AM
javascript null Why

JavaScript有不少怪癖和难以理解的地方。其中Why does JavaScript have null? (Translation) - Tianbeiya& Why does JavaScript have null? (Translation) - Tianbeiya就比较有意思。既然有了为什么JavaScript还要弄一个Why does JavaScript have null? (Translation) - Tianbeiya?

相等比较

让我们开始由具有看看下面的对比探索Why does JavaScript have null? (Translation) - Tianbeiya和Why does JavaScript have null? (Translation) - Tianbeiya:

Why does JavaScript have null? (Translation) - Tianbeiya >= 0;//false 

Why does JavaScript have null? (Translation) - Tianbeiya <= 0;//false 

Why does JavaScript have null? (Translation) - Tianbeiya == 0;//false 

Why does JavaScript have null? (Translation) - Tianbeiya < 0;//false 

Why does JavaScript have null? (Translation) - Tianbeiya > 0;//false
Copy after login

Why does JavaScript have null? (Translation) - Tianbeiya

Why does JavaScript have null? (Translation) - Tianbeiya如何能既大于或等于零,又小于或等于零,但又不等于零?(是不是开始怀疑计算机了,也不是很严谨么)

要理解这一点,首先需要知道JavaScript如何处理这些比较。在上面的例子中使用了两种不同类型的运算符: 相等运算符[Equality Operators](==,===,!= and!===)和关系运算符[Relational Operators](>,<,> =和<=)。 两者的工作方式不同。

相等运算符在对象层面进行比较。 如果两个操作数,运算符左右的事物是不同的类型,则使用严格的比较(===或!==)。 因为Why does JavaScript have null? (Translation) - Tianbeiya是一个对象,0是一个数字,它们不相等。

在关系运算符的情况下,两个操作数都转换为相同的类型。 在例子中给一个数字。当前情景下,JavaScript正在执行以下操作:

Number(Why does JavaScript have null? (Translation) - Tianbeiya) >= 0; //true
Copy after login

进一步解释一下. Number(Why does JavaScript have null? (Translation) - Tianbeiya) 返回值 0 ,然后0 等于 0.

我们来用Why does JavaScript have null? (Translation) - Tianbeiya试下同样的例子:

Why does JavaScript have null? (Translation) - Tianbeiya >= 0;//false 
Why does JavaScript have null? (Translation) - Tianbeiya <= 0;//false 
Why does JavaScript have null? (Translation) - Tianbeiya == 0;//false 
Why does JavaScript have null? (Translation) - Tianbeiya < 0;//false 
Why does JavaScript have null? (Translation) - Tianbeiya > 0;//false
Copy after login

Why does JavaScript have null? (Translation) - Tianbeiya

首先直觉想到,这应该会是相同的结果。 虽然JavaScript是一样的,但结果却再次是不一样的。JavaScript先将Why does JavaScript have null? (Translation) - Tianbeiya 转换为一个数字, 但Number(Why does JavaScript have null? (Translation) - Tianbeiya )不是0而是NaN。 JavaScript规范中明确,与NaN 的每个比较都会是false,甚至与 NaN进行比较也是。

当然算法上可能还是有很多不同,当前的解释也能说明一些问题

为什么存在Why does JavaScript have null? (Translation) - Tianbeiya?

JavaScript需要一个空值吗? 虽然可以编写整个应用程序而不使用Why does JavaScript have null? (Translation) - Tianbeiya,但通常它是有一个Why does JavaScript have null? (Translation) - Tianbeiya的地方。 使用的区别是意图。 一个空值是非常中性的,其中一个Why does JavaScript have null? (Translation) - Tianbeiya值通常是无意的,只是默认值。

 例如在检索一条数据的函数中。 当该数据不存在时,此函数返回Why does JavaScript have null? (Translation) - Tianbeiya。否则返回数据。 通过这种方式,可以判断该函数返回的值是否被设置为Why does JavaScript have null? (Translation) - Tianbeiya,或者包含结果的变量根本不设置。

 换句话说: Why does JavaScript have null? (Translation) - Tianbeiya !== Why does JavaScript have null? (Translation) - Tianbeiya

The above is the detailed content of Why does JavaScript have null? (Translation) - Tianbeiya. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to display child categories on archive page of parent categories How to display child categories on archive page of parent categories Apr 19, 2025 pm 11:54 PM

Do you want to know how to display child categories on the parent category archive page? When you customize a classification archive page, you may need to do this to make it more useful to your visitors. In this article, we will show you how to easily display child categories on the parent category archive page. Why do subcategories appear on parent category archive page? By displaying all child categories on the parent category archive page, you can make them less generic and more useful to visitors. For example, if you run a WordPress blog about books and have a taxonomy called "Theme", you can add sub-taxonomy such as "novel", "non-fiction" so that your readers can

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

How to recover data after SQL deletes rows How to recover data after SQL deletes rows Apr 09, 2025 pm 12:21 PM

Recovering deleted rows directly from the database is usually impossible unless there is a backup or transaction rollback mechanism. Key point: Transaction rollback: Execute ROLLBACK before the transaction is committed to recover data. Backup: Regular backup of the database can be used to quickly restore data. Database snapshot: You can create a read-only copy of the database and restore the data after the data is deleted accidentally. Use DELETE statement with caution: Check the conditions carefully to avoid accidentally deleting data. Use the WHERE clause: explicitly specify the data to be deleted. Use the test environment: Test before performing a DELETE operation.

Centos stops maintenance 2024 Centos stops maintenance 2024 Apr 14, 2025 pm 08:39 PM

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

How to write oracle database statements How to write oracle database statements Apr 11, 2025 pm 02:42 PM

The core of Oracle SQL statements is SELECT, INSERT, UPDATE and DELETE, as well as the flexible application of various clauses. It is crucial to understand the execution mechanism behind the statement, such as index optimization. Advanced usages include subqueries, connection queries, analysis functions, and PL/SQL. Common errors include syntax errors, performance issues, and data consistency issues. Performance optimization best practices involve using appropriate indexes, avoiding SELECT *, optimizing WHERE clauses, and using bound variables. Mastering Oracle SQL requires practice, including code writing, debugging, thinking and understanding the underlying mechanisms.

How to import oracle database How to export oracle database How to import oracle database How to export oracle database Apr 11, 2025 pm 02:30 PM

Oracle database migration mainly relies on expdp and impdp tools. 1. expdp is used to export data. Its syntax is concise but has rich options. Pay attention to directory permissions and file size to avoid export failures. 2. impdp is used to import data. It is necessary to ensure that the target database space is sufficient, the character set is consistent and there are no objects with the same name. The remap_schema parameter can be used to resolve conflicts. 3. Parallel, query, network_link, exclude and other parameters can be used to optimize the migration process; 4. Large database migration requires attention to network environment, database resource utilization and batch migration strategies to improve efficiency and reduce risks. Only by mastering these steps and techniques can you

What are the tools to connect to mongodb What are the tools to connect to mongodb Apr 12, 2025 am 06:51 AM

The main tools for connecting to MongoDB are: 1. MongoDB Shell, suitable for quickly viewing data and performing simple operations; 2. Programming language drivers (such as PyMongo, MongoDB Java Driver, MongoDB Node.js Driver), suitable for application development, but you need to master the usage methods; 3. GUI tools (such as Robo 3T, Compass) provide a graphical interface for beginners and quick data viewing. When selecting tools, you need to consider application scenarios and technology stacks, and pay attention to connection string configuration, permission management and performance optimization, such as using connection pools and indexes.

Detailed explanation of docker principle Detailed explanation of docker principle Apr 14, 2025 pm 11:57 PM

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

See all articles