博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在JavaScript中,如何判断值的类型?
阅读量:2510 次
发布时间:2019-05-11

本文共 1098 字,大约阅读时间需要 3 分钟。

JavaScript has a few built-in types, including numbers, strings, booleans, objects.

JavaScript具有一些内置类型,包括数字,字符串,布尔值,对象。

Using the typeof operator we can check what is the type of a value assigned to a variable.

使用typeof运算符,我们可以检查分配给变量的值的类型是什么。

For example:

例如:

typeof 'test'

Note that it’s not a function, it’s an operator, so parentheses are not required.

请注意,它不是函数,而是运算符,因此不需要括号。

Using it, we will get a string back, returning one of the following values:

使用它,我们将返回一个字符串,返回以下值之一:

  • 'number'

    'number'

  • 'string'

    'string'

  • 'boolean'

    'boolean'

  • 'undefined'

    'undefined'

  • 'bigint'

    'bigint'

  • 'symbol'

    'symbol'

  • 'object'

    'object'

  • 'function'

    'function'

Note that there is no null type, and

请注意,没有null类型,并且

typeof null

will return 'object'.

将返回'object'

Arrays will return 'object' too:

数组也将返回'object'

typeof [ 1 , 2 , 3 ] //'object'

Functions are a special kind of objects, as we can add properties and methods to functions:

函数是一种特殊的对象,因为我们可以向函数添加属性和方法:

const talk = () => {}talk . test = true

but they have their own value 'function' if we use the typeof operator.

但是如果我们使用typeof运算符,它们将具有自己的值'function'

翻译自:

转载地址:http://uomgb.baihongyu.com/

你可能感兴趣的文章
VNPY- VnTrader基本使用
查看>>
VNPY - CTA策略模块策略开发
查看>>
VNPY - 事件引擎
查看>>
MongoDB基本语法和操作入门
查看>>
学习笔记_vnpy实战培训day04_作业
查看>>
OCO订单(委托)
查看>>
学习笔记_vnpy实战培训day06
查看>>
回测引擎代码分析流程图
查看>>
Excel 如何制作时间轴
查看>>
matplotlib绘图跳过时间段的处理方案
查看>>
vnpy学习_04回测评价指标的缺陷
查看>>
设计模式10_桥接
查看>>
量化策略回测DCCV2
查看>>
mongodb查询优化
查看>>
五步git操作搞定Github中fork的项目与原作者同步
查看>>
git 删除远程分支
查看>>
删远端分支报错remote refs do not exist或git: refusing to delete the current branch解决方法
查看>>
python multiprocessing遇到Can’t pickle instancemethod问题
查看>>
APP真机测试及发布
查看>>
通知机制 (Notifications)
查看>>