Why can’t the following argument be made against the claim that primitive types are immutable in Javascript:
var $b = false;
$b = true;
alert($b); //-> true
I am misunderstanding what it means for a variable to immutable.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Values are immutable; variables are not.
$b = truechanges$bto contain thetruevalue.The immutable
falsevalue is not changed.Some languages support immutable variables as well (C++’s
const, Java’sfinal, or C#’sreadonly); Javascript does not.