前端黑魔法
前端黑魔法
介绍一下我学到的前端的一些奇奇怪怪的知识
- == vs ===
在 js 中比较两个变量时,== 比较两个变量的值是否相等
=== 不仅比较值是否相等,还+-30-1——————————————–比较两个变量的类型是否一直
a = 0, b = 0, c = ‘0’
a == b => true, a == c => true, b === c => false
- !. 非空类型断言符 这个符号表示对象后面的属性一定不是 null 或者 undefined
https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#non-null-assertion-operator-postfix-
?.
a?.b
if a is not null, return a.b
else return a (null or undefine)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
??
a ?? b
if a is nullish return b
But if a is not null , then return a,
if a is null, return b
b is likely a default value.
Only effective when a is null/undefined
!!
a !! b = a!(!b)