Why can't we use var here instead of const

const myConcat = (arr1, arr2) => {

You can. There’s no point using var, but there’s also no reason why you can’t, unless this is an FCC challenge which requires that you use const.

what will happen if we use var. What will change.

You’ll be able to reassign the identifier myConcat.

var myConcat = (arr1, arr2) => { // do stuff

var myConcat = 'Hello' // oops, just overwrote myConcat

Whereas with const

const myConcat = (arr1, arr2) => { // do stuff

const myConcat = 'Hello' // Error, myConcat is already defined

There also are a few other rules surrounding the difference between var and const (or let), but that’s the one that has the most immediate effect. There’s literally no point using var though, it gains you nothing and makes it easier for subtle errors to creep in.

1 Like