分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 软件开发

JS基础_非布尔值的与或运算

发布时间:2023-09-06 01:16责任编辑:蔡小小关键词:暂无标签
 1 <!DOCTYPE html> 2 <html> 3 ????<head> 4 ????????<meta charset="UTF-8"> 5 ????????<title></title> 6 ?????????7 ????????<script type="text/javascript"> 8 ?????????????9 ????????????/*10 ?????????????* && || 非布尔值的情况11 ?????????????* ????12 ?????????????* ?- 对于非布尔值进行与或运算时,会先将其转换为布尔值,然后再运算,并且返回原值13 ?????????????* ????14 ?????????????* ?- 与运算:15 ?????????????* ????????- 如果第一个值为true,则必然返回第二个值16 ?????????????* ????????- 如果第一个值为false,则直接返回第一个值17 ?????????????* 18 ?????????????* ????- 或运算19 ?????????????* ????????- 如果第一个值为true,则直接返回第一个值20 ?????????????* ????????- 如果第一个值为false,则返回第二个值21 ?????????????* 22 ?????????????*/23 ????????????24 ????????????//true && true25 ????????????//与运算:如果两个值都为true,则返回后边的,谁在后边返回谁26 ????????????var result = 5 && 6;27 ????????????console.log("result = "+result); //6 28 ????????????29 ????????????30 ????????????//与运算:如果两个值中有false,则返回靠前的false31 ????????????//false && true32 ????????????result = 0 && 2;33 ????????????console.log("result = "+result); //034 ????????????35 ????????????result = 2 && 0;36 ????????????console.log("result = "+result); //037 ????????????38 ????????????39 ????????????//false && false40 ????????????result = NaN && 0;41 ????????????result = 0 && NaN;42 ????????????console.log("result = "+result); //043 ????????????44 ????????????//-----------------------------------------------------------------------------45 ????????????46 ????????????//true || true47 ????????????//如果第一个值为true,则直接返回第一个值48 ????????????result = 2 || 1;49 ????????????console.log("result = "+result); //250 ????????????51 ????????????result = 2 || NaN;52 ????????????console.log("result = "+result); //253 ????????????54 ????????????result = 2 || 0;55 ????????????console.log("result = "+result); //256 ????????????57 ????????????58 ????????????//如果第一个值为false,则直接返回第二个值59 ????????????result = NaN || 1;60 ????????????console.log("result = "+result); //161 ????????????62 ????????????result = NaN || 0;63 ????????????console.log("result = "+result); //064 ????????????65 ????????????result = "" || "hello";66 ????????????console.log("result = "+result); //hello67 ????????????68 ????????????result = -1 || "你好";69 ????????????console.log("result = "+result); //-170 ????????????71 ????????????72 ????????</script>73 ????????74 ????</head>75 ????<body>76 ????</body>77 </html>

JS基础_非布尔值的与或运算

原文地址:http://www.cnblogs.com/ZHOUVIP/p/7652796.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved