1

As a newbie i would like to know that if we do

function square(x) { return x*x; }

and

var s = square;
square(4);

So basically the s is a new function in which the square function is copied? cause i am confused in this. please help.

3
  • s is a new function in which the square function is copied? No, now s references to the square Commented Oct 20, 2015 at 3:26
  • @Tushar i want to know like is s a new function? Commented Oct 20, 2015 at 3:27
  • No, both are pointing to the same function, Have you heard of soft-link/shortcut in OS, it is the same concept Commented Oct 20, 2015 at 3:28

2 Answers 2

2

so basically the s is a new function in which the square function is copied?

No, s is simply another "name" with which you can refer to the same function.

s === square will be true, i.e. both bindings will refer to the same object.

Sign up to request clarification or add additional context in comments.

3 Comments

so you mean S is like a reference to that function,,
correct @MarcAndreJiacarrini, it is a variable point to the same spot in memory
A better word for "name" might be "alias". I think that was what you were going for, right?
0

S is not a new function. It is merely a pointer to the square function. They are both the same.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.