简体   繁体   中英

In JavaScript, can you use toLowerCase() after a variable is declared in a conditional statement?

Whenever I use toLowerCase() in JavaScript, I seem to always have problems such as typeError: "x" is not a function.

Ex.

var x = "Pie";
if (x.toLowerCase() = "pie") {
 // Code isn't executed
}

use this

var x = "Pie";
if (x.toLowerCase() == "pie") {
  // Code isn't executed
}

notice the double equal ( == ) or you can use ( === ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM