Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Is this correct?

Is this correct?

Is this correct?

According to page 26 in this PDF tutorial from Tutorials Point, it says the result would be "true", but is actually giving "false".
It goes like this:

Assume variable A holds 10 and variable B holds 20, then:

1. && (Logical AND)
If both the operands are non-zero, then the condition becomes true.
Ex: (A && B) is true.

Along the lines above, also in the same page, the one below is not giving what they said it would.

! (Logical NOT)
Reverses the logical state of its operand. If a condition is true, then the Logical NOT operator will make it false.
Ex: ! (A && B) is false.

document.write("!(a && b) => ");
result = (!(a && b));

But it's giving me TRUE.

Also this one is not giving the expected result, in page 21:

var a = 10;
var b = 20;
var c = "Test";
var linebreak = "<br />";
a = a++;
document.write("a++ = ");
result = a++;
b = b--;
document.write("b-- = ");
result = b--;

RE: Is this correct?

The first comparison is correctly returning false for me. Make sure both a and b are defined before you do the comparison.

As to the ++ issue. That's has always been confusing. The gist of it, is that a=a++, will assign the value of a before it increments a by 1.
Basically a++ returns a which is assigned to a. And then it adds 1 to a.

A better explanation here(though it may still not make sense):
Difference betwen a++ and ++a
You can perform the addition directly without assigning it, and the variable will be updated.


//no assignment. 

Your other option is to change the order:



This will ad 1 to a first, and then assign the resulting value back to a.

Phil AKA Vacunita
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close