_
and
$
.
NaN**0
is
1
.
NaN
is not equal to itself. Use
isNaN()
to check for
NaN
.
typeof null
is
object
(bug).
typeof alert
is
function
.
undefined
becomes
NaN
and
null
becomes
0
.
0
,
''
,
null
,
undefined
and
NaN
, becomes
false
and other values become
true
.
===
and
!==
as they disallow type
coercion.
null
and
undefined
are equal to each other
but not to any other value.
!!
can be used to
convert a value to boolean type.
||
operator finds the
first truthy value.
&&
operator finds the
first falsy value.
??
operator finds the first
defined(neither null
nor
undefined
) value.
switch
uses strict equality
check.
let obj = new Object(); // "object constructor" syntax
let obj = {}; // "object literal" syntax
obj.prop = 5;
obj[hello + "world"] = 7; // computed property
delete obj.prop; // to remove a property
// property value shorthand
let user = {
name, // same as name:name
age: 30
};
// iterate over an object
for (let key in obj) {
// ...
}
in
operator.
Object.assign()
.
JSON.parse(JSON.stringify(obj))
or
structuredClone(obj)
(comparison).
new
.
function Obj(name) {
this.name = name;
}
let obj = new Obj("Abhinav");
new
or without it, using a
special new.target
property.
new
.
return
is called with an
object, then the object is returned instead of
this
. If
return
is called with a
primitive, it's ignored.
?.
is a
safe way to access nested object properties, even if an intermediate
property doesn't exist. ?.
syntax
has three forms: obj?.prop
- returns
obj.prop
if
obj
exists, otherwise
undefined
.
obj?.[prop]
- returns
obj[prop]
if
obj
exists, otherwise
undefined
.
obj.method?.()
- calls
obj.method()
if
obj.method
exists, otherwise
returns undefined
.