Javascript 参数比较赢';行不通

Javascript 参数比较赢';行不通,javascript,Javascript,一切正常-除了这个if-else语句外,一切正常: else if ((day = 0 || day = 6) && (hour <= 19)) { greeting = "We wish you a nice weekend and a nice " + Weekdays[day] + "."; } 如果((天=0 | |天=6)和&(小时使用=进行比较(通过值)和=分配值 因此,在您的情况下,应该是: ... else if ((day ==

一切正常-除了这个if-else语句外,一切正常:

    else if ((day = 0 || day = 6) && (hour <= 19)) {
  greeting = "We wish you a nice weekend and a nice " +
  Weekdays[day] + ".";
  }

如果((天=0 | |天=6)和&(小时使用
=
进行比较(通过
)和
=
分配值

因此,在您的情况下,应该是:

 ...
 else if ((day == 0 || day == 6) && (hour <= 19)) {
   greeting = "We wish you a nice weekend and a nice " +
   Weekdays[day] + ".";
 }
 ...

你用的是
=
而不是
=
。虽然它应该是
==
而不是
=
@killgar,但我现在查了一下,似乎你可以同时使用这两个。==只是“相等”而===是“严格相等”的
var a = 10; // assigns value 10 to variable `a`

"1"==1      // true => Since == compares by value

"1"===1     // false => Since === compares by both type and value. In this case although value is 1, both are of different types (string and integer)