• xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!


    js types & primitive & object

    js 数据类型

    typeof null
    // "object"
    
    typeof undefined
    // "undefined"
    
    typeof Symbol('symbol desc')
    // "symbol"
    typeof Symbol
    // "function"
    
    typeof `strings`
    // "string"
    
    typeof 123
    // "number"
    typeof NaN;
    // "number"
    
    typeof BigInt(1n);
    // "bigint"
    
    typeof true
    // "boolean"
    
    typeof function() {}
    // "function"
    
    typeof (() => {})
    // "function"
    typeof () => {}
    // Uncaught SyntaxError: Malformed arrow function parameter list
    
    typeof {}
    // "object"
    
    typeof []
    // "object"
    
    typeof NaN
    // "object"
    
    

    NaN

    Number.isNaN(NaN)
    // true
    isNaN(NaN)
    // true
    
    Number.isNaN('hello world');
    // false
    isNaN('hello world'); 
    // true
    
    Number.isNaN(``)
    // false
    Number.isNaN(0)
    // false
    
    isNaN(``)
    // false
    isNaN(0)
    // false
    
    

    NaN === NaN;        // false
    Number.NaN === NaN; // false
    isNaN(NaN);         // true
    isNaN(Number.NaN);  // true
    Number.isNaN(NaN);  // true
    
    function valueIsNaN(v) { return v !== v; }
    valueIsNaN(1);          // false
    valueIsNaN(NaN);        // true
    valueIsNaN(Number.NaN); // true
    
    
    isNaN('hello world');        // true
    
    Number.isNaN('hello world'); // false
    
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NaN

    Array

    Array.isArray([])
    // true
    Array.isArray({})
    // false
    
    

    null

    const nl = null;
    // null
    nl === null
    // true
    
    
    typeof null          // "object" (not "null" for legacy reasons)
    typeof undefined     // "undefined"
    null === undefined   // false
    
    null  == undefined   // true
    
    null === null        // true
    
    null == null         // true
    
    !null                // true
    isNaN(1 + null)      // false
    isNaN(1 + undefined) // true
    
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null

    Symbol

    typeof Symbol('symbol desc')
    // "symbol"
    
    typeof Symbol
    // "function"
    
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol

    function

    const obj = {};
    const func = () => {};
    
    obj instanceof Object;
    // true
    func instanceof Object;
    // true
    
    func instanceof Function;
    // true
    obj instanceof Function;
    // false
    
    
    

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof

    Object

    Object.prototype.toString

    Object.prototype.toString.apply(obj) 
    // "[object Object]"
    
    Object.prototype.toString.apply(func)
    // "[object Function]"
    
    

    Object.prototype.toString.apply

    Object.prototype.toString.apply(Symbol(`s desc`))
    // "[object Symbol]"
    
    Object.prototype.toString.apply(NaN)
    // "[object Number]"
    
    Object.prototype.toString.apply(123)
    // "[object Number]"
    
    Object.prototype.toString.apply(BigInt(1n))
    // "[object BigInt]"
    
    Object.prototype.toString.apply(null)
    // "[object Null]"
    
    Object.prototype.toString.apply(``)
    // "[object String]"
    
    Object.prototype.toString.apply(true)
    // "[object Boolean]"
    
    Object.prototype.toString.apply(undefined)
    // "[object Undefined]"
    
    

    Object.prototype.toString.call

    Object.prototype.toString.call(NaN)
    "[object Number]"
    Object.prototype.toString.call(undefined)
    "[object Undefined]"
    Object.prototype.toString.call(true)
    "[object Boolean]"
    Object.prototype.toString.call({})
    "[object Object]"
    Object.prototype.toString.call(func)
    "[object Function]"
    Object.prototype.toString.call(obj)
    "[object Object]"
    Object.prototype.toString.call(Symbol())
    "[object Symbol]"
    Object.prototype.toString.call(null)
    "[object Null]"
    Object.prototype.toString.call(123)
    "[object Number]"
    Object.prototype.toString.call(BigInt(1n))
    "[object BigInt]"
    
    

    The latest ECMAScript standard defines 8 data types:

    7 data types that are primitives:

    Boolean
    Null
    Undefined
    Number
    BigInt (ES10 / 2019 新增)
    String
    Symbol (ES6 / ES2015 新增)

    1 data type that is reference:

    Object

    function() {}
    () => {}
    

    typeof

    'number'
    'string'
    'boolean'
    'undefined'
    'bigint'
    'symbol'
    'object'
    'function'

    refs

    https://flaviocopes.com/difference-primitive-types-objects/

    https://flaviocopes.com/javascript-value-type/

    TypeScript types

    types & primitive & object

    http://javascript.xgqfrms.xyz/pdfs/TypeScript Language Specification.pdf

      // const a: Object = [- 7 , 1, 5, 2, -5, 1];
      // const b: Object = [2, 3, 4, 2, 4];
      // const c: Object = [2, 3, 4, 3, 2];
      // const a: Number[] = [- 7 , 1, 5, 2, -5, 1];
      // const b: Number[] = [2, 3, 4, 2, 4];
      // const c: Number[] = [2, 3, 4, 3, 2];
      const a: number[] = [- 7 , 1, 5, 2, -5, 1];
      const b: number[] = [2, 3, 4, 2, 4];
      const c: number[] = [2, 3, 4, 3, 2];
    
    

    ©xgqfrms 2012-2020

    www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    iOS开篇——UI之UILabel
    关于Block初识与自己的认识
    浅拷贝与深拷贝
    关于MacBook Pro选购
    准备考试 暂时停更
    Objective-C代理
    Objective-C协议初识
    Objective-C内存管理
    通讯录习题
    软件工程第二次作业 词频统计
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/13054867.html
Copyright © 2020-2023  润新知