Hi FE !
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
Ai
git
前端面试题
前端小tip
  • vite
  • webpack
npm
  • vue2
  • vue3
react
GitHub
  • B015-检测一个变量是String类型

B015-检测一个变量是String类型

typeof

function isString(str) {
  return typeof(str) === 'string' ? true : false
} 

constructor

function isString(str) {
  return str.constructor === String ? true : false
}

toString

function isString(str) {
  return Object.prototype.toString.call(str) == '[object String]' ? true: false
}

Edit this page
最近更新: 2025/6/27 02:24
Contributors: qdleader
qdleader
本站总访问量 129823次 | 本站访客数 12人