# Can someone tell me how can we do this?

//How can assign b to 5?

``````function fun(a = 10,b) {

console.log(a, b)
}
fun(5)
``````

Your function takes 2 parameters. Thus, if you want to give `b` a value, you have to pass an argument to `a` first.

`fun(undefined, 5)`

Thanks for reply any other way to do that?

Nope. No other way unless you only give your function 1 parameter.

Just making it clearer to you, what they said:

``````function fun(a = 10, b=5){
console.log (a , b)
}
``````

The point is: if you want to `b=5`, you should define it on the creation of your function, like above. But, this doesn’t mean that `a = 10` and `b = 5 ` forever. You can pass other values as well and it will still work. Javascript is very flexible with parameters, though you can call your function like this:

``````fun(5, 6)
``````

wich will result in a console like this `5 6`.

But you can call the function without any parameters(that’s when your `a = 10` and `b = 5` will take place). Look:

``````fun()
``````

will display ` 10 5`

Hope it helps you.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.