Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
is object mutable in javascript? If yes, why the object of string is immutable then?

In javascript only object and arrays are mutable and remaining are primitive type which are immutable. However if we create an object of string,then it can't be mutated. why is that?

var a = new String("abc")
a.toUpperCase();
console.log(a) /*wont print "ABC" and prints an object with String:abc. Concludes 
that string object is immutable.*/
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In general, yes, objects are mutable.

The reason that "string objects" - created with new String - are not mutable is that string objects result in objects which have an internal StringData property:

Set S.[[StringData]] to value.

That StringData is what is retrieved when the string object is coerced back to a primitive.

If the interpreter provided a way to change this StringData internal slot - then these sorts of objects would effectively be mutable. (Similarly, Set.add changes a Set's internal slot, and the same sort of mechanism exists for many other objects in JS - an exposed method changes values held in internal slots.)

But

a.toUpperCase();

alone wouldn't do anything - toUpperCase returns a new string. There are no methods (in standard implementations) that exist that can alter a string object's StringData internal slot - all you can do is create a new string object with a different StringData.

You could also strongly consider just not using string objects at all.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!