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

133
Views
Javascript, what happens when we assign value to read-only data property such as string length?

Suppose we have a string, length is read-only data property of string. What happen if we unintentionally assign value to length property of string? Why javaScript return those value as a result?

for example if we run this part of code:

var str="test";
console.log(str.length)
console.log(str.length=3)

output should be like this:

4
3

the third line of code returns 3, My question is why assignment in javaScript returns right side of operand not left side of it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The assignment operator always returns the right-hand value. Hence, passing the expression inside the console.log function returns the right-hand value, in your case 3.

Assigning any value to the length property of a string has no effect.

let myString = "Hello,World!";

myString.length = 4;

console.log(myString);
// expected output: "Hello,World!"

console.log(myString.length);
// expected output: 12

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!