Jump to content

About logical operator


jtified

Recommended Posts

I'm not sure if you are using "&&" and "||" the way they are intended to be used in javascript. As far as I know, they are intended to be used as part of a conditional statement, like "if" or a "while" loop....

 

if (var1 10) for example.

 

If you are wanting to combine the two variables, for example, 10+20, or "cat" + "dog" you'll need to use "+". Combining booleans will give you their value (false = 0, true = 1).

 

---

 

I will point out that:

-- if you try to use "20 && 10", the result will always be the last variable ("10")

-- if you use " "cat && "dog" " (you need "" around the text, because they are strings) you'll get the last variable ("dog")

-- if you use "true && false", you'll get false if any one of the variables are false (order doesn't matter) and true otherwise.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...