Is number in JavaScript immutable?
javascript
Solution
They are immutable because they are copied by value.
When you do
var x = 4;
x += 1;
you haven't changed the number `4` into the number `5`. You have changed the value stored in the variable `x` from `4` to `5`.
Problem
Possible Duplicate: javascript numbers- immutable I read Douglas Crockford's book JavaScript: the Good Parts. It says the number in JavaScript is immutable. But numbers in JavaScript is copied by value and we can use operator ++ to change the value. So why say it's immutable? and further, if it's immutable, why numbers are copied by value?