Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda