0

Why is value of variable behaving this way? Pass-by-reference [Solved]

Hi. I AM A LITTLE CONFUSED AS TO WHY THE VALUE OF A IS 6 AND NOT 10. WHY IS THIS HAPPENING EXACTLY? THANKS FOR THE HELP :) AND SORRY FOR THE CAPITALIZATION , I CANNOT TURN IT OFF ON MY IPAD WHEN WRITING IN THIS FIELD, STRANGE AS IT MAY SEEM... https://code.sololearn.com/ca177a168A19/?ref=app

28th Feb 2021, 3:23 PM
The_Fox
The_Fox - avatar
3 odpowiedzi
+ 3
The variable b has overwritten the a, because it was declared in the function last.
28th Feb 2021, 3:52 PM
JaScript
JaScript - avatar
+ 2
you are passing the same variable reference to both arguments, so when you assign first a to 10 and second b to 6, you refer to same emplacement, so later value remain ^^ by same way, if you output value of c, you'll get 12 and not 16 ;)
28th Feb 2021, 3:50 PM
visph
visph - avatar
+ 1
Thank you very much :) ++
28th Feb 2021, 4:14 PM
The_Fox
The_Fox - avatar