Skip to content

true + true == true 的结果是什么?为什么? #40

Open

Description

@CodeRookie262
No description provided.

Activity

  1. changed the title [-]true + true == true 的结果是什么?为什么[/-] [+]true + true == true 的结果是什么?为什么?[/+] on Feb 23, 2021
  2. CodeRookie262 commented on Feb 24, 2021

    @CodeRookie262
    OwnerAuthor

    除了字符数,数值外的类型在加法运算中都会进行隐式类型转换为数值,所以 true 最终会变为 1,即 2 == true;
    在数值类型与其他类型的比较之间会把非数值类型隐式类型转换为数值,2 == 1,故最终结果为 false。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions