0
    let variable1="hello";
function func1(variable){
    variable="hello hello";
}
func1(variable1);
console.log("after function: "+variable1);

let object1={
    property1:"hello2"
}
function func2(obj){
    obj.property="hello object";
}
func2(object1);
console.log("after function:" +object1.property);

I have this code, the first console.log() returns

hello

but second console.log() returns

hello object

So I understood javascript cannot change and update variable but it can change and update property of object. But why and how?

game lover
  • 114
  • 2
  • 7
  • Probably also relevant: [What is the scope of variables in JavaScript?](https://stackoverflow.com/q/500431) – VLAZ Mar 16 '20 at 09:58
  • @VLAZ thank you, I think the link you sent me will help me much to be a better web developer – game lover Mar 16 '20 at 10:04

0 Answers0