zoukankan      html  css  js  c++  java
  • 检测一个变量是否为字符串

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    <script type="text/javascript">
        var str='123asd';
        //法1
        console.log(typeof str==='string'); //true
        //法2
        console.log(str.constructor===String); //true
    
        console.log(str instanceof String); //false
        //法3
        console.log(Object.prototype.toString.call(str)==='[object String]')
    
    
    </script>
    
    </body>
    </html>
    
  • 相关阅读:
    idea
    C#
    mysql
    .net5
    .net5
    .net5
    .net5
    .net5
    .net5
    .net5
  • 原文地址:https://www.cnblogs.com/sakura-sakura/p/6826459.html
Copyright © 2011-2022 走看看