Git Product home page Git Product logo

Comments (4)

SimplyY avatar SimplyY commented on July 28, 2024

+1..

from markyun.

wagnlinzh avatar wagnlinzh commented on July 28, 2024

@kmCha null 是对象类型的,

typeof null //object

关于null和undefined的历史渊源 可以看一下这篇文章:

http://www.ruanyifeng.com/blog/2014/03/undefined-vs-null.html

: )

from markyun.

kmCha avatar kmCha commented on July 28, 2024

@wagnlinzh null是对象类型算是一个bug吧,他会被typeof解析为object是因为底层对null的二进制表示全为0,而typeof判定为object的条件是低三位为0,他自然就会被解析成object了,对于基本数据类型的官方说明:
http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.2
https://developer.mozilla.org/en-US/docs/Glossary/Primitive

from markyun.

wagnlinzh avatar wagnlinzh commented on July 28, 2024

@kmCha 不好意思我纠正一下, 翻了一下书,的确是我弄混淆了, Null 是基本类型的. (^_^)

完整的说, JS中的数据类型分两类: 简单类型(也就是基本类型)和复杂类型

  • 简单类型(基本类型)5种: Undefined, Null, Boolean, Number, String
  • 复杂类型: Object.
typeof null //object

是因为null被认为是一个空对象的指针(对象引用)

from markyun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.