+ 1
Basic Js question
Hello guys, I have a Js question that seems to be basic but I cannot figure it out, please help me. function print(f) { let first = 'Mary'; console.log(f)} When I executed it with a variable declared in the function scope as argument, I got an error. print(first); //--> first is not defined Why is this happening? I thought I should be able to access the print scope since I am executing the print function.
3 Answers
+ 1
I understand it, just being curious about why can the variable inside the function not be accessed.
+ 6
No, because you have no variable named "first" outside the function,
You have to place the "first" outside the function
+ 2
hold on.. you did not call the function first.
second you passing f but where is f in your function.
when you pass argument you don't have to declare it again because it ia already declared.
https://code.sololearn.com/WsBfDZ4ZT8t7/?ref=app