Skip to content

JavaScript - Pass-by-value || Page 92 #9

Open
@adityathebe

Description

@adityathebe

var age = 7;
function addOne (x) {
x = x +1;
}
addOne(age);
document.write(age);

I'm gonna break this down the way I have understood.

So, we have a function called addOne which adds 1 to the value it accepts, right?
And then we call the function with an argument of the value 7. So, now the function adds 1 to 7 and age is 8.
But why is it that when I print out the value of age, it prints out 7 ??

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions