JS篇(002)-JavaScript 中如何检测一个变量是一个 String 类型?
2024-10-20 13:46:08
答案:三种方法(typeof、constructor、Object.prototype.toString.call())
解析:
①typeof
typeof('123') === "string" // true
typeof '123' === "string" // true
②constructor
'123'.constructor === String // true
③Object.prototype.toString.call()
Object.prototype.toString.call('123') === '[object String]' // true
最新文章
- python写红包的原理流程包含random,lambda其中的使用和见简单介绍
- Resharper 检测所有NullReferenceExceptions(空指针)
- flume 1.4的介绍及使用示例
- problem-record-mysql
- OMG点菜系统
- RAD 版本迁移工具,不怕升级麻烦了。
- Jsoncpp 数组的使用
- 洛谷P2320 鬼谷子的钱袋
- leetcode学习笔记--开篇
- Eclipse的修改编码插件使用
- 编程是一项需要时间来掌握的技能(Anders的经验)
- 清除缓存、开启IO统计
- 【opengl】OpenGL中三维物体显示在二维屏幕上显示的变换过程
- javascript系列之DOM(三)---事件
- if和for的应用
- 关于“System.Data.OleDb.OleDbException,外部数据库驱动程序 (1) 中的意外错误。”的解决方案
- Linux 学习 (五) 压缩与解压缩命令
- synchronized同步方法《二》
- 【python基础】迭代器和生成器函数
- 织梦替换ueditor百度编辑器,支持图片水印 教程
热门文章
- linux忘记密码-进入单用户模式修改密码
- 链接mysql数据库报错:2003-cant connect to Mysql server on ‘localhost’(10038)
- TypeScript 学习之路
- 微信小程序 switch
- defineProperty和Proxy
- Java枚举类的学习
- npm vue-router安装报错
- 服务器IPMI地址及用户名密码
- python 的钩子函数
- 【文献阅读】An efficient motion planning based on grid map: Predicted Trajectory Approach with global path guiding