Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2K views

Java Script

The document discusses JavaScript spread and rest operators. It explains that the rest parameter collects remaining elements into an array, and the spread operator expands elements. It also covers using arguments before rest parameters, and the nullish coalescing operator for assigning default values.

Uploaded by

logesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Java Script

The document discusses JavaScript spread and rest operators. It explains that the rest parameter collects remaining elements into an array, and the spread operator expands elements. It also covers using arguments before rest parameters, and the nullish coalescing operator for assigning default values.

Uploaded by

logesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Spread Operators & Rest Parameter

Another example

y@pne agypanamepg nfenedepYn.oae.eogcsasesms.u.s


const arr = I 's 213^4153

# Rest Parameter comet c- a. b. → •


rests -
-
arr

elements into
A collects all
remaining array
* p, , none,

Arguments keyword
Before rest parameters existed, to get all the arguments in a function we used arguments which is an array-like
object.
function someFunction() {
return arguments;
}

someFunction("joykare", 100, false);


someFunction returns the arguments and their indexes, [Arguments] { '0': 'joykare', '1': 100, '2': false }.

The downside of using the arguments keyword is that, it returns an array-like object; this means you
essentially cannot perform any array-methods like; Array.filer, Array.map. Another pitfall, is that we cannot use
arguments in arrow functions. This is because arrow-functions do not have their own this, and hence no
arguments object either.

https://scotch.io/bar-talk/javascripts-three-dots-spread-vs-rest-operators543

* Spread operator

unpaeke 1 expands elements

it be used in
→ not
only corsage can
any
iteration like
array string object, ,

g- concatenating garage
copying arrays
adding new elements / fields
Toothy or
Falsy
methods
for assigning
Nallish
Coalescing Operators? :D default Valens

Its side of
* a
logical operator raters Rite it when

kits is null 00
undefined

* usually is used for assigning default value when

fits is null ,
undefined ,
"
,O , NaN

optimal chaining operator


let
foo =f some
Prop : hi }

log Cfoo some


Prop
?
tooppossccase ??
" "
console . -

• NA '

↳ HI

logcfoo Prop ?• toopporcase.CI ? ?


"

console . - some Other NA ;


"

↳ NA

You might also like