I am told arr1 is not defined. But arr2 is ??
To do;
Rewrite the myConcat function which appends contents of arr2 to arr1 so that the function uses arrow function syntax.
var myConcat = function(arr1, arr2) {
return arr1.concat(arr2);
};
console.log(myConcat([1, 2], [3, 4, 5]));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36
I’m not sure that I understand what you are meaning by “outer parentheses”. You asked about an error and I explained what caused that. Parentheses had nothing to do with it.
The issue with your code wasn’t that, it was this:
myConcat(arr1.concat(arr2))
It was trying to use a variable out of scope. “arr1” is only defined inside the function definition. This is outside the function definition.
If this does not answer your question, please boil this down to the code in question, say exactly what you think it should do, and exactly what you think it should do instead.
Being able to describe and explain code problems is an important skill for a developer.
You call that function but you provide only ONE argument
myConcat(arr1.concat(arr2))
At this point, JavaScript has no idea what arr1 and arr2 are. You’ve never defined them anywhere, causing the undefined error.
Now you call the function again within a console.log, and this time you provide two arrays, so the myConcat function knows what’s arr1 and arr2, and returns the concatinated array:
Thnks again KS !!, yes i tried both. With and without the (). the code part with myConcat(arr1.concat(arr2))
is just not to be added. and i must repeat the scope lessons again !!.
Scope is a confusing concept when you are starting out, and JS has some oddities. Don’t worry, you’ll get there. Just keep working, learning, and asking questions, like you’re doing.