1

JS does not have public/private variables, but everything is accessible from pretty much anywhere.

Is it possible to check what other variables reference another variable?

var firstVar = "Hello";
someObject.secondVar = firstVar;
checkReferences(someObject.secondVar);

=> firstVar

Or something along these lines.

2
  • You can't access variables from everywhere. It depends on the scope of the variable. Commented Nov 20, 2013 at 15:32
  • No, but you are freer than in many other languages. Not everywhere, but pretty much. Commented Nov 20, 2013 at 15:34

2 Answers 2

2

someObject.secondVar would have the same value as firstVar, but it doesn't reference it. If you change the value of one, it won't change the value of the other.

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

Comments

0

Sorry for asking a question I was close to finding out the answer to.

I should have asked whether or not JS passes by reference or value. It's by value, until you pass Objects {}. So the question does not really make sense.

This answer is good reading for anyone who was wondering the same as me

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.