惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
T
Tenable Blog
C
CERT Recently Published Vulnerability Notes
Cisco Talos Blog
Cisco Talos Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
P
Privacy & Cybersecurity Law Blog
Know Your Adversary
Know Your Adversary
T
The Exploit Database - CXSecurity.com
Latest news
Latest news
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
F
Fortinet All Blogs
Engineering at Meta
Engineering at Meta
Simon Willison's Weblog
Simon Willison's Weblog
The Register - Security
The Register - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
H
Help Net Security
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
S
Schneier on Security
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
P
Privacy International News Feed
S
Secure Thoughts
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
C
Cybersecurity and Infrastructure Security Agency CISA
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
博客园 - Franky
T
Tor Project blog
G
GRAHAM CLULEY
博客园 - 【当耐特】
Jina AI
Jina AI
Security Archives - TechRepublic
Security Archives - TechRepublic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
A
About on SuperTechFans
Hacker News - Newest:
Hacker News - Newest: "LLM"

博客园 - 永不言败

JavaScript 语言基础知识点总结(思维导图) 关于Visual Studio项目系统属性中的宏 MongoDb的相关资料 javascript apply 和call的区别,javascript设计模式 Adding a QR Code Reader in Flex on Android castle 在mvc3如何注入 Castle Automatic Transaction Management python webpy模板介绍 使用 asp.net mvc和 jQuery UI 控件包 webpy demo核心代码 Howto create a System.Linq.Expressions.Expression for Like 实体框架继承关系。很好 淘宝店铺图片数据迁移核心代码 mvc扩展 ASP.NET MVC 2 Templates C#、VB.NET使用HttpWebRequest访问https地址(SSL)的实现 Nhibernate继承 Castle 容器注入学习例子 event.x,event.clientX,event.offsetX区别
javaScript 运算符 && 和 || 的返回值
永不言败 · 2009-12-04 · via 博客园 - 永不言败

今天才知道,原来 && 和|| 的返回值是这样计算的
&&首先计算其左边的表达式,如果它的值为false或可被转换为false(null、NaN、0或undefined),那么将返回左边表达式的值,否则,它将计算右边的表达式, 并返回这个表达式结果作为 &&运算的结果。
||首先计算其左边的表达式,如果它的值不为false或不可被转换为false(null、NaN、0或undefined),那么将返回左边表达式的值,否则,它将计算右边的表达式,

并返回这个表达式结果作为||运算的结果。

代码

<HTML>
 
<HEAD>
  
<TITLE> 运算符&&和||的返回值 </TITLE>
 
</HEAD>
 
<BODY>
 &&首先计算其左边的表达式,如果它的值
<font color=blue>为false</font><font color=blue>可被转换为false</font><font color=red>(null、NaN、0或undefined)</font>,那么将返回左边表达式的值,否则,它将计算右边的表达式,
 并返回这个表达式结果作为 &&运算的结果。
<br>
||首先计算其左边的表达式,如果它的值
<font color=blue>不为false</font><font color=blue>不可被转换为false</font><font color=red>(null、NaN、0或undefined)</font>,那么将返回左边表达式的值,否则,它将计算右边的表达式,
 并返回这个表达式结果作为 ||运算的结果。
 
<hr>
  
<SCRIPT LANGUAGE="JavaScript">
    
function dwn(s)
    {
        document.write(s 
+ "<br/>");
    }

    dwn(

"null && 33 = " + (null && 33));//null
    dwn("NaN && 33 = " + (NaN && 33));//NaN
    dwn("0 && 33 = " + (0 && 33));//0
    dwn("undefined && 33 = " + (undefined && 33));//undefined
    dwn("true && 33 = " + (true && 33));//33
    dwn("false && 33 = " + (false && 33));//false
    dwn("33 && 44 = " + (33 && 44));//44
    dwn("---------");

    dwn(

"null || 33 = " + (null || 33));//33
    dwn("NaN || 33 = " + (NaN || 33));//33
    dwn("0 || 33 = " + (0 || 33));//33
    dwn("undefined || 33 = " + (undefined || 33));//33
    dwn("true || 33 = " + (true || 33));//true
    dwn("false || 33 = " + (false || 33));//33
    dwn("33 || 44 = " + (33 || 44));//33
    
</SCRIPT>
<hr>
同时javascript中 if (expression) statement; 语句的判断也是
<br>
看 expression 是否是不是 false 或 能不能转换成false(null、NaN、0或undefined)
<br>
如果能 则不执行 statement; 否则就执行 statement;
<hr/>
<SCRIPT LANGUAGE="JavaScript">
<!--
    
if (null)
        dwn(
"null test");
    
if (0)
        dwn(
"0 test");
    
if (undefined)
        dwn(
"undefined test");
    
if (NaN)
        dwn(
"NaN test");
    
if (444)
        dwn(
"444 test");
//-->
</SCRIPT>
<hr>
由此可见,if (a==b)dosth();和a==b&
&dosth();或a!=b||dosth()等价</BODY>
</HTML>