JavaScript ES6 / ES2015 - [07] Default Params & Spread Operator

preview_player
Показать описание
Lets take a look at how to use default parameters in ES6. We will also look at the spread operator

SUPPORT THIS CHANNEL WITH A CUP OF COFFEE PER MONTH:

ONE TIME DONATIONS:
Рекомендации по теме
Комментарии
Автор

yeah this is a bad example of the spread operator. It doesn't matter if you do the .apply(null, args) or not, if you do the console log and call the variable it's scope is applied and it is used in the function either way. And it's just does a normal console.log. I would consider reshooting this video with a better example. I've enjoyed all your other videos, they have been very informative and simple.

Chrisdraws
Автор

Brad I think what you could to do there is:
function test(){
console.log([...args1, ...args2])
}
test() so both arrays could be merged into one, cause in the example you showed even if you don't use the spread operator we still get the same result. It doesn't have an effect. And since we're using the global variables we don't need to pass them into the function anymore.

braulioandre
Автор

Hello. I have one question: why you use $ symbol in paramenters of function?

carthago_delenda_est
Автор

Why in 0:28 the parameter name is declared with '$'?

manueljordan
Автор

One important thing when discussing spread operator is that they keep the original data structure immutable which is awesome if you are using frameworks like react(+redux) where application state must be immutable. You also get a lot cleaner and readable code as a bonus (something which is impossible to achieve with all heavily bloated modern frameworks)

dew_reddit
Автор

@Traversy Media, you can eliminate "function ()" and replace it with just
greet = (greeting="Hello world") => console.log(greeting)
i think its better way to write ES6 way

stevemaniar
Автор

So the function uses the global variables, there is no need to pass them into the function. I'm confused!

TT-udgf
Автор

@brad can you please clarify this video in a better way. I think console logging and just calling test() does it already. Why am I using ... For?

FauzulChowdhury
Автор

The code works without using the spread operator. Does not gives clarity as to why to use the spread operator. Thanks

iceman
Автор

At 4:21 I got the same result without using the ... when calling test. ea: test(args1, args2); - printed 1, 2, 3, 4, 5, 6.

stefanage
Автор

let arg = [1, 2, 3]
function checkTheFunction() {
console.log(arg)
}


function myFunc(value) {
console.log(value)
}
checkTheFunction.apply(arg) // [1, 2, 3]
checkTheFunction(...arg) // [1, 2, 3]
myFunc(...arg) // 1
myFunc(arg) // [1, 2, 3]


Please explain, How it works ?

goretushar
Автор

The pirple node.js course I have got it for free. This ad sucked me up.

AliAkbar-vote
Автор

bad example !! speard operator has no effect at all in your example. Please remove this video and reshoot with better example.

arifsultan
Автор

For the first time, I found your mistakes. You should reconsider making a video on spread operator and rest operator. I respect your knowledge sir. Human does mistakes. Please, remove this video and make a right one on this topic. Otherwise people will leave your channel.

AliAkbar-vote