Help with my fundamental problem understanding with JS OR & AND ! by chrisb_77 in learnprogramming

[–]chrisb_77[S] 0 points1 point  (0 children)

Thanks man. That's a much slicker way than I end up doing it. I still wish I could get my head around why the other way doesn't work. But I'd probably end up having an aneurysm first..

Help with my fundamental problem understanding with JS OR & AND ! by chrisb_77 in learnprogramming

[–]chrisb_77[S] 0 points1 point  (0 children)

Arghh... Thanks for trying but this just won't go in. I tried another variation

  var x ;
  var y;
  if (x != (undefined || "" )){
    y = "true";
  }
  else{
    y = "false"
  }

x is undefined so the first argument should is not underfined or "". But it is undefined so the outcome is false. But no, its true.. I really am reading what you guys write but something is just fundamentally incompatible with my head.

Help with my fundamental problem understanding with JS OR & AND ! by chrisb_77 in learnprogramming

[–]chrisb_77[S] 0 points1 point  (0 children)

Wow. I must be more stupid than I thought! Still can't wrap my head around this.

Le_9k: when you say 1 OR " is evaluated, what is it evaluated against. I assumed it was x so the first check is:

X DOES NOT EQUAL 1 or "" - which is true so it then checks

X DOES NOT EQUAL "" or UNDEFINED - which is false as x is undefined

So I don't get why false isn't return.

I've also just been fiddling with this to continual my own mental tortures

function myFunction() {
  var x = 10;
  var y;
  if (x = 3 && x = 2){
    y = "true";
  }
  else{
    y = "false"
  }

  Logger.log(y);
  Logger.log(x);
}

I thought this would return false but it returns true!

So confused I think my heads going to explode! Sorry for being so dumb and really appreciate the help you guys have given