+ 1
*HELP* In Javascript , What does Uncaught ReferenceError: Invalid left-hand side in assignment MEAN??
I tried changing the value of a variable which was in another function... https://code.sololearn.com/W2Fpuok7s4VJ/?ref=app
4 odpowiedzi
+ 1
Trinity [Exams]
In a regular assignment operation, whatever is to the left of = operator is said "left-hand side" (short as LHS), and whatever is to the right of = operator is said "right-hand side" (short as RHS).
The error message tells you that `myfunction(this.a)` (the LHS) is not a good candidate to accept the value 20 (the RHS).
I think this is because the LHS here is a function, which usually returns something rather than accepting something (being assigned a value).
Is this the whole part of the code?
+ 1
I just created a new code to show the error
+ 1
Trinity [Exams]
However it is possible to assign a value to an object's attribute (property). So we need to use the object rather than the object constructor function (myFunction).
https://www.sololearn.com/learn/JavaScript/1152/
function myFunction(n) {
this.a = n;
}
window.onload = function() {
var obj = new myFunction(42);
console.log(obj.a); // 42
obj.a = 20;
console.log(obj.a); // 20
obj.a *= 100;
console.log(obj.a); // 2000
}
+ 1
Ipang Thank YOU VERY MUCH!!