JS Code Error Help

Does Anyone know what this means??

I am making a website and I keep getting this error. I was coding a thing for my website where if the user is using a mobile device, it will link to another website that is made for mobile users. All my code is listed below. (The code works by the way I just have no idea what it means and when I look it up I get even more confused.

‘Uncaught ReferenceError: Invalid left-hand side in assignment’


function isMobile() {
  return /Android|iPhone/i.test(navigator.userAgent);


if (isMobile() = false); {


html(if it helps)…:

<!DOCTYPE html>
<html lang="en">

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>The World Of Numbers</title>
  <link href="style.css" rel="stylesheet" type="text/css" />
  <link rel="icon" type="image/x-icon" href="R (1).png">
  <script src="script.js"></script>

I have linked all js and css(doubt that makes a big deal) files, and the file “mindex.html” is the file that I am linking to.

Thanks for the help!

1 Like

Notice here:

The = sign in JavaScript means you are assigning a value to something else. So you’re basically saying “If (random set that isn't valid since you can't set a function to a boolean, especially not in an if call), then . . .” Which just doesn’t make sense.

So basically, to say “If x equals y” in JavaScript, you must use the double equals (==)

So change:

if (isMobile() = false); {


if (isMobile() == false); {

Simple mistake, that’s all.

Though I do wonder, by saying == false, you are redirecting your non-mobile users to a different page, and keeping your mobiles on the same page. Is that the intended behavior? If not, you can change the false to true or even omit the whole == false part (since isMobile() would still be returning the value of true, letting the condition pass)

1 Like

Wow thanks, that fixed it. I also guess i made a mistake when doing it as false, well it works now and now I have a mobile friendly website. Thanks for all your help. :wink:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.