javascript 中的比较大小,兼 typeof()用法

javascript中的排序: 1.不同类型 比 类型 (字符串 > 数字)   2.同类型:(字符串  比 按字母顺序 )(数字 比 大小)

测试:

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Javascript typeof</title>
</head>
<body>

<script type="text/javascript">
    var a = "11111";
    var b = "22222";
    var c = 22222;
    var str = 'string';

    var s1 = "abb";
    var s2 = "abcd";
    var s3 = "-";
    
    console.log('typeof', typeof a);
    console.log('typeof b', typeof b);  
    console.log('typeof c', typeof c);
    console.log('typeof b > typeof c', typeof b > typeof c);
    console.log('typeof a === typeof b', typeof a === typeof b);
    console.log('typeof a === typeof c', typeof a === typeof c);
    console.log('typeof a === str', typeof a === str);
    console.log('a-b', a-b);
    console.log('a-c', a-c);
    console.log('s1-s2', s1-s2);
    console.log('s1>s2 ?', s1>s2);
    console.log('s1<s2 ?', s1<s2);

    console.log('parseInt(s1)', parseInt(s3));
    console.log('parseFloat(s1)', parseFloat(s3));
    console.log('Number(s1)', Number(s3));

    console.log('a-0', a-0);
    console.log('s3-0', s3-0);

</script>
    
</body>
</html>
复制代码
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Javascript typeof</title>
</head>
<body>

<script type="text/javascript">
    var a = "11111";
    var b = "22222";
    var c = 22222;
    var str = 'string';

    var s1 = "abb";
    var s2 = "abcd";
    var s3 = "-";
    
    console.log('typeof', typeof a);
    console.log('typeof b', typeof b);  
    console.log('typeof c', typeof c);
    console.log('typeof b > typeof c', typeof b > typeof c);
    console.log('typeof a === typeof b', typeof a === typeof b);
    console.log('typeof a === typeof c', typeof a === typeof c);
    console.log('typeof a === str', typeof a === str);
    console.log('a-b', a-b);
    console.log('a-c', a-c);
    console.log('s1-s2', s1-s2);
    console.log('s1>s2 ?', s1>s2);
    console.log('s1<s2 ?', s1<s2);

    console.log('parseInt(s1)', parseInt(s3));
    console.log('parseFloat(s1)', parseFloat(s3));
    console.log('Number(s1)', Number(s3));

    console.log('a-0', a-0);
    console.log('s3-0', s3-0);

</script>
    
</body>
</html>
复制代码

 

输出结果:

 

posted @   驸马爷  阅读(316)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示