简体   繁体   English

falsey var在console.log中显示未定义

[英]falsey var showing undefined in console.log

 var statusDatesDescending = ko.computed(function () { var result = cachedSortExpression() === "StringValue"; logger.log(result); return result; }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

The following provides this in the console when result is false: 当result为false时,以下内容将在控制台中提供:

logger.log("DESCENDING: ", result); logger.log(“ DESCENDING:”,result); DESCENDING: undefined 降序:未定义

The following provides this in the console when result is true: 当结果为true时,以下内容将在控制台中提供:

logger.log("DESCENDING: ", result); logger.log(“ DESCENDING:”,result); DESCENDING: true 降序:正确

What you might seeing is the return from console.log , as seen here, if you are using an interactive console. 如果您使用的是交互式控制台,则可能会看到console.log的返回,如此处所示。

在此处输入图片说明

Notice how false is logged before undefined . 注意在undefined之前如何记录false The console.log call executes, logging to the console, and then returns undefined. 执行console.log调用,登录到控制台,然后返回undefined。 The return value of the call is shown because the interactive console always shows the result of any functions you enter into it. 之所以显示该调用的返回值,是因为交互式控制台始终显示您输入到其中的所有功能的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM