Skip to content Skip to sidebar Skip to footer

Expression Expected Near If Condition

I keep getting expression expected error in VS near if(isnullor ........ if (value) { if (isNullOrUndefined(x.value) && isNullOrUndefined(x.value2)) { x.minMark + '-'

Solution 1:

You haven't provided much context, but this part is suspect for a couple of reasons:

if(isNullOrUndefined(x.value) && isNullOrUndefined(x.value2))
{
  x.minMark + '-' + a+ '*'
  + x.b+ ' ' + '+' + ' ' + x.c+ ' '
  + val+ '+' + ' ' + '*' + x.s
  + ' ' + '+' + ' ' + ' ' + ' ' + x.val4
}
  1. Because of Automatic Semicolon Insertion, you always want to put the + at the end of the previous line rather than the beginning of the next line, because at the beginning of the next line it can be the unary plus operator. With ASI, if adding a semicolon at the end of a line doesn't make the syntax invalid, it's usually added (but not always, the rules are slightly complicated).

  2. You have an expression statement¹ there (a series of additions) whose result is never used for anything. Maybe you meant to use x.minMark = or x.minMark += or something rather than x.minMark +.


¹ An expression statement is an expression used as a statement. JavaScript is slightly unusual in that it has an (almost) unlimited expression statement (any expression can be used as a statement other than a couple of edge cases that would be ambiguous and have to be wrapped in a parenthesis expression), unlike some other languages (including Java) that have limited ones that only allow some expressions (like method calls) to be statements.


Post a Comment for "Expression Expected Near If Condition"