function formatNum(num) {
if (num >10) {
num = 10;
console.log(num + " >10");
}
};
formatNum(number_var);
If I try to use above function to determine whether a number surpasses a certain amount, it notices that it is indeed above that value, but won't overwrite it with 10
.
The weird thing is that the console does print out 10 > 10
, which makes it seem like it did change the value. Referencing the value later on still shows the value 200
, for example. If I replace the part where I call the function like this:
if (number_var >10) {
number_var = 10;
}
This way does work, which makes me think I'm missing something like a function not able to change a variable's value.