Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

ReferenceError: invalid assignment left-hand side

Nuestros voluntarios aún no han traducido este artículo al Español. Únete a nosotros y ayúdanos a traducirlo

Message

ReferenceError: invalid assignment left-hand side

Error type

ReferenceError.

What went wrong?

There was an unexpected assignment somewhere. This might be due to a mismatch of a assignment operator and a comparison operator, for example. While a single "=" sign assigns a value to a variable, the "==" or "===" operators compare a value.

Examples

if (Math.PI = 3 || Math.PI = 4) { 
  console.log('no way!');
}
// ReferenceError: invalid assignment left-hand side

var str = 'Hello, '
+= 'is it me '
+= 'you\'re looking for?';
// ReferenceError: invalid assignment left-hand side

In the if statement, you want to use a comparison operator ("=="), and for the string concatenation, the plus ("+") operator is needed.

if (Math.PI == 3 || Math.PI == 4) { 
  console.log('no way!'); 
}

var str = 'Hello, ' 
+ 'from the ' 
+ 'other side!';

See also

Etiquetas y colaboradores del documento

 Colaboradores en esta página: fscholz
 Última actualización por: fscholz,