typeof
是用来求值结果作为其操作数的类型结果字符串,属于一元运算符。还可以替代语法是在括号中使用操作数,这对于检查JavaScript表达式返回值的类型非常有用。下面web建站小编给大家详细介绍一下具体使用方法!
基本用法:
typeof "web"; // 'string' typeof 22; // 'number' typeof NaN; // 'number' typeof Infinity; // 'number' typeof true; // 'boolean' typeof false; // 'boolean' typeof [1, 2]; // 'object' typeof {age: 22}; // 'object' typeof null; // 'object' typeof undefined; // 'undefined' typeof String; // 'function' typeof Boolean; // 'function' typeof Number; // 'function' typeof Object; // 'function' typeof Function; // 'function' typeof person; // 'function'
检测值是否存在在不同环境:
if (typeof window !== 'undefined') { // 浏览器 }; if (typeof process !== 'undefined') { // Node.js } if (typeof $ !== 'undefined') { // jQuery }
jquery如何判断某个元素是否存在(判断元素是否存在某个属性)
js如何获取当前对象的类型(number/string/boolean)
上面是“js中typeof语法有什么作用”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3637.html
workflows工作流
森林里一只空灵的犀鸟ComfyUI工作流
未来椅子3D产品ComfyUI工作流
一张由表情符号组成的照片ComfyUI工作流
葡萄庄园白葡萄酒ComfyUI工作流
在森林中心有一座蛇形的房子ComfyUI工作流
一只白色小猫comfyui工作流
一个浑身皮毛看起来像丘巴卡的3d动漫人物
一名男子跪在月球岩石表面看见小行星碰撞
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!