Invalid left-hand side in assignment expression

parsing error: invalid left-hand side in assignment expression react
invalid left-hand side in assignment jquery
invalid left-hand side in assignment node js
eslint invalid left-hand side in assignment expression
invalid assignment left-hand side google script
invalid left-hand side in assignment eval
invalid left-hand side in object destructuring pattern
invalid left hand side in assignment maple

New person here working on a toy problem building a function that converts a string to camelcase anywhere there is a dash or an underscore. I have almost everything worked out except the second to last line of the function where I am trying to change the characters at each index (from my index array) to uppercase before I return the string. The error I am getting is bad assignment from the left side, but I'm not sure why. I've console logged both sides of the assignment and they seem to be doing what I want, but the assignment itself isn't working. Thank you for any help!

Here is the code:

function toCamelCase(str){
  var stringArray = str.split('');
  var indexArray = [];
  stringArray.forEach(character => {
    if (character === '-' || character === '_') {
      var index = str.indexOf(character);
      str = str.slice(0, index) + str.slice(index+1)
      indexArray.push(index);
    }
    return character;
  })
  indexArray.forEach(index => {stringArray.splice(index, 1)});
  string = stringArray.join('');
  indexArray.forEach(index => {string.charAt(index) = string.charAt(index).toUpperCase()});
  return string;
}

The problem is with using string.charAt() on the left hand side. That is not possible as you're trying to assign something to the result of a function, all in the same call. Store the value of string.charAt() in an intermediary variable and it should work. Check the code below for a working example, using a slightly different approach:

function toCamelCase(str){
  var stringArray = str.split('');
  var indexArray = [];
  stringArray.forEach(character => {
    if (character === '-' || character === '_') {
      var index = str.indexOf(character);
      str = str.slice(0, index) + str.slice(index+1)
      indexArray.push(index);
    }
    return character;
  });
  indexArray.forEach(index => {stringArray.splice(index, 1)});
  return stringArray.map((char, index) => {
    return indexArray.includes(index) ? char.toUpperCase() : char;
  }).join('');
}

JavaScript, The Invalid Left-Hand Assignment error is a sub-object of ReferenceError and is thrown, as the name implies, when code attempts to perform an invalid assignment somewhere. 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.

Ah thank you both for pointing me in the right direction. Instead of joining it back to a string I took advantage of it being an array already and just looped through that first.

This code worked...

function toCamelCase(str){
  var stringArray = str.split('');
  var indexArray = [];
  stringArray.forEach(character => {
    if (character === '-' || character === '_') {
      var index = str.indexOf(character);
      str = str.slice(0, index) + str.slice(index+1)
      indexArray.push(index);
    }
    return character;
  })
  indexArray.forEach(index => {stringArray.splice(index, 1)});
  indexArray.forEach(index => {stringArray[index] = stringArray[index].toUpperCase()});
  var string = stringArray.join('');
  return string;
}

ReferenceError: Invalid left-hand side in assignment, You have to use == to compare (or even === , if you want to compare types). A single = is for assignment. if (one == 'rock' && two == 'rock')  TS2364: Invalid left-hand side of assignment expression. Ask Question Asked 3 years, 4 months ago. Active 3 years, 4 months ago. Viewed 1k times 2. a is a mutable

For taking an approach by iterating the characters, you could use a flag for the following upper case letter.

function toCamelCase(str) {
    var upper = false;

    return str
        .split('')
        .map(c => {
            if (c === '-' || c === '_') {
                upper = true;
                return '';
            }
            if (upper) {
                upper = false;
                return c.toUpperCase();
            }
            return c;
        })
        .join('');
}

console.log(toCamelCase('foo----bar_baz'));

Syntax Error: "Invalid Left-hand Side in assignment.", Syntax Error: "Invalid Left-hand Side in assignment." I am unsure what else is necessary in my code. My syntax is as follows: var isEven = function(number) {. The Invalid Left-Hand Assignment error is a sub-object of ReferenceError and is thrown, as the name implies, when code attempts to perform an invalid assignment somewhere.

Assigning variable to value of a function (Invalid left-hand side in , variable to value of a function (Invalid left-hand side in assignment Error) FixedExpress returns the current expression (a string) with the  For example, the left-hand operand of an assignment is expected to produce a reference. The behaviour of assignment could, instead, be explained entirely in terms of a case analysis on the syntactic form of the left-hand operand of an assignment operator, but for one difficulty: function calls are permitted to return references.

JavaScript Error Invalid Assignment Left Hand Side, invalid assignment left-hand side JavaScript error. This error occurs because of the mismatch of a comparison and assignment operator. Syntax Error: "Invalid Left-hand Side in assignment." To get rid of it just fix the comparison: isNan(number) == true or isNan(number) === true or get rid of the == true or === true and just use: isNan(number) as a comparision with true is always what it was before e.g. if isNan(number) is false: false === true --> false and if it is true:

Bad assignment, In ESLint the warning has always been "Invalid left-hand side in assignment" with an assignment expression where you would normally expect a conditional:. RangeError: invalid array length; RangeError: invalid date; RangeError: precision is out of range; RangeError: radix must be an integer; RangeError: repeat count must be less than infinity; RangeError: repeat count must be non-negative; ReferenceError: "x" is not defined; ReferenceError: assignment to undeclared variable "x"

Comments
  • Possible duplicate of Why does chartAt() cause an "Invalid left-hand side in assignment" error in JavaScript?