-3

I wanna know what means the following line in javascript:

$variable1 && $variable2

The line is exactly like a said, without nothing more.

Justin Meiners
  • 10,754
  • 6
  • 50
  • 92
Dyego Nery
  • 424
  • 1
  • 4
  • 8
  • 6
    http://stackoverflow.com/questions/8720645/operator-in-javascript – Justin Meiners Aug 20 '13 at 18:32
  • 3
    $variable1 and $variable2 are 2 bool values and its checking if they both are true – Venkata Krishna Aug 20 '13 at 18:33
  • 9
    @Krishna They aren't necessarily boolean values – Mike Park Aug 20 '13 at 18:33
  • 4
    Are you sure this isn't PHP? Javascript variables don't normally start with `$` unless they are jQuery objects (that is, NOT boolean) – John Dvorak Aug 20 '13 at 18:34
  • 2
    -1 because I suspect you've confused your languages – John Dvorak Aug 20 '13 at 18:36
  • @Krishna the values _may_ or _may_ not be an instanceof Boolean of course. – Dimitris Zorbas Aug 20 '13 at 18:38
  • @climbage & Dmitris - true – Venkata Krishna Aug 20 '13 at 18:38
  • 1
    A lot of down-votes here, but none of the answers on this page or even the supposed "existing question" describe what the && operator really does--which is to return the expression on left if it can be evaluated as `false`, otherwise return the expression on the right. – Peter Aug 20 '13 at 18:45
  • 1
    If this really is JS, and the said expressions are not a part of any statement, this does nothing. `&&` operator is executed, but the return value is not used anywhere. Maybe you'd post some more code around this line? – Teemu Aug 20 '13 at 18:47
  • Please check this [fiddle](http://jsfiddle.net/5rzs6/), there is a `a && b` on a line alone, though it's a part of a statement. – Teemu Aug 20 '13 at 19:00

3 Answers3

0

$variable1 and $variable2 are 2 bool values (rightly pointed in comments not always) and its checking if they both are true.

They can also be a jQuery selector's length .. For example:

   var $variable1 = someselector.length;
    if($variable1)
    {
        //Some code
    }

in the above statement length is an int.. but used to check if the selector exists or not.

Venkata Krishna
  • 14,926
  • 5
  • 42
  • 56
0

$variable1 && $variable2

"Do $variable1 AND $variable2 BOTH equate to true?"

Lil' Bits
  • 898
  • 2
  • 9
  • 24
0

$variable1 AND $variable2

&&- logical AND

Sobin Augustine
  • 3,639
  • 2
  • 25
  • 43