博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
typeof运算符_JavaScript typeof运算子
阅读量:2521 次
发布时间:2019-05-11

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

typeof运算符

In JavaScript, any value has a type assigned.

在JavaScript中,任何值都有分配的类型。

The typeof operator is a unary operator that returns a string representing the type of a variable.

typeof运算符是一元运算符,它返回表示变量类型的字符串。

Example usage:

用法示例:

typeof 1 //'number'typeof '1' //'string'typeof {name: 'Flavio'} //'object'typeof [1, 2, 3] //'object'typeof true //'boolean'typeof undefined //'undefined'typeof (() => {}) //'function'typeof Symbol() //'symbol'

JavaScript has no “function” type, and it seems funny that typeof returns 'function' when we pass it a function.

JavaScript没有“函数”类型,当我们将其传递给函数时, typeof返回'function'似乎很有趣。

It’s one quirk of it, to make our job easier.

这是一个怪癖,使我们的工作更轻松。

If you don’t initialize the variable when you declare it, it will have the undefined value until you assign a value to it.

如果在声明变量时未对其进行初始化,则该变量将具有undefined值,直到您为其分配值为止。

let a //typeof a === 'undefined'

typeof works also on object properties.

typeof也适用于对象属性。

If you have a car object, with just one property:

如果您有一个只有一个属性的car对象:

const car = {  model: 'Fiesta'}

This is how you check if the color property is defined on this object:

这是检查color属性是否在此对象上定义的方法:

if (typeof car.color === 'undefined') {  // color is undefined}

翻译自:

typeof运算符

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

你可能感兴趣的文章
Android 面试题整理总结(二)Java 集合
查看>>
学习笔记_vnpy实战培训day02
查看>>
学习笔记_vnpy实战培训day03
查看>>
VNPY- VnTrader基本使用
查看>>
VNPY - CTA策略模块策略开发
查看>>
VNPY - 事件引擎
查看>>
MongoDB基本语法和操作入门
查看>>
学习笔记_vnpy实战培训day04_作业
查看>>
OCO订单(委托)
查看>>
学习笔记_vnpy实战培训day06
查看>>
回测引擎代码分析流程图
查看>>
Excel 如何制作时间轴
查看>>
matplotlib绘图跳过时间段的处理方案
查看>>
vnpy学习_04回测评价指标的缺陷
查看>>
iOS开发中遇到的问题整理 (一)
查看>>
Linux(SUSE 12)安装jboss4并实现远程访问
查看>>
Neutron在给虚拟机分配网络时,底层是如何实现的?
查看>>
netfilter/iptables全攻略
查看>>
Overlay之VXLAN架构
查看>>
Eclipse : An error occurred while filtering resources(Maven错误提示)
查看>>