javascript中typeof的用法是什么? [英] What is the usage of typeof in javascript?

查看:59
本文介绍了javascript中typeof的用法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

typeof 返回原始数据类型,但是我不明白为什么要在javascript中使用它?

typeof returns the primitive data type but I am not getting why it is used in javascript?

推荐答案

我不明白为什么要在javascript中使用它?

I am not getting why it is used in javascript?

typeof 用于

返回原始数据

例如,如果我想知道某事是否未定义,我可以做

For example, if I wanted to know if something was undefined, I could do

if (typeof object === 'undefined')

进行检查,因为如果它是未定义的,则没有数据类型(因为它是未定义的).这通常就是为什么 typeof 除了用于日志记录目的,查看通过ajax接收到的内容,或者用于使函数接受可以具有不同类型的参数并使用检查该类型的原因.typeof

to check because if it is undefined there is no datatype (because it's undefined). This is generally why typeof would be used other than for logging purposes, to see what is received through ajax, or for making functions that accept a parameter that can have different types and checking that type with typeof, etc.

这篇关于javascript中typeof的用法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆