I have the function change(x) which takes an integer and changes its value
function change(x) {
x=26;
}
Then I make a variable and I try to change its value
window.onload=function(){
var a = 10;
change(a);
console.log(a);
}
a doesn't change as I would expect. Is it possible to achieve this behaviour in JavaScript in a simple way without using return? I would prefer to avoid objects and globals.
Here is my whole code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function change(x) {
x=26;
}
window.onload=function(){
var a = 10;
change(a);
console.log(a);
}
</script>
</body>
</html>