Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实用类 #5

Open
q837477816 opened this issue Apr 6, 2018 · 0 comments
Open

实用类 #5

q837477816 opened this issue Apr 6, 2018 · 0 comments

Comments

@q837477816
Copy link
Owner

q837477816 commented Apr 6, 2018

+运算符的使用

1.可以将字符串显式地转换为数字,例如
+ "123" // 123
+ "123abc" // NaN
2.可以将日期对象强制转换为数字,返回结果为时间戳,例如
+ new Date() // 1523021852154
// 上述代码等价为以下代码
new Date().getTime() // 1523021852154
// 或者
Date.now() // 1523021852154

假值

  • undefined
  • null
  • false
  • +0、-0和NaN
  • ""

逻辑运算符&&与||

在js中,&&和||运算符的返回值并不一定是布尔类型,而是两个操作树其中一个的值。例如:
var a = 42;
var b = "abc";
var c = null;

a || b; // 42
a && b; // "abc"

c || b; // "abc"
c && b; // null

null和undefined之间的想等比较

null == undefined; // true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant