-
Notifications
You must be signed in to change notification settings - Fork 23
Variables-and-Operators-Task #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| const exp2 = "dog" == "dog"; // TODO: ADD YOUR EVALUATION HERE --> true | ||
|
|
||
| const exp3 = true != false; // TODO: ADD YOUR EVALUATION HERE --> | ||
| const exp3 = true != false; // TODO: ADD YOUR EVALUATION HERE --> false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return true instead
| const exp5 = 5 > 4; // TODO: ADD YOUR EVALUATION HERE --> true | ||
|
|
||
| const exp6 = null == undefined; // TODO: ADD YOUR EVALUATION HERE --> | ||
| const exp6 = null == undefined; // TODO: ADD YOUR EVALUATION HERE --> false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return true, because both of these values are falsey values by default, meaning that false == false.
This would return false only when using the strict equals operator === which would also check for the types resulting in them being false.
| const exp8 = "false" == false; // TODO: ADD YOUR EVALUATION HERE --> false | ||
|
|
||
| const exp9 = NaN === NaN; // TODO: ADD YOUR EVALUATION HERE --> | ||
| const exp9 = NaN === NaN; // TODO: ADD YOUR EVALUATION HERE --> true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should evaluate to false.
The reason NaN === NaN evaluates to false is because according to the IEEE 754 standard (which JavaScript follows for floating-point arithmetic), NaN values are considered unordered. This means that they are not equal to any other value, including other NaN values.
| const exp11 = false && !false; // TODO: ADD YOUR EVALUATION HERE --> false | ||
|
|
||
| const exp12 = "apple" > "pineapple"; // TODO: ADD YOUR EVALUATION HERE --> | ||
| const exp12 = "apple" > "pineapple"; // TODO: ADD YOUR EVALUATION HERE --> apple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the expression "apple" > "pineapple", JavaScript compares the strings character by character from left to right. Since "a" comes before "p" in the alphabet, "apple" is considered "less than" "pineapple". Therefore, "apple" > "pineapple" evaluates to false.
| const exp12 = "apple" > "pineapple"; // TODO: ADD YOUR EVALUATION HERE --> apple | ||
|
|
||
| const exp13 = "2" > "12"; // TODO: ADD YOUR EVALUATION HERE --> | ||
| const exp13 = "2" > "12"; // TODO: ADD YOUR EVALUATION HERE --> false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should evaluate to true.
Even though numerically 2 is less than 12, since we're comparing strings, the comparison is based on their lexicographical order. In this case, the string "2" is considered greater than the string "12" because "2" comes after "1" lexicographically.
| const exp13 = "2" > "12"; // TODO: ADD YOUR EVALUATION HERE --> false | ||
|
|
||
| const exp14 = undefined == null; // TODO: ADD YOUR EVALUATION HERE --> | ||
| const exp14 = undefined == null; // TODO: ADD YOUR EVALUATION HERE --> false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should evaluate to true.
Both null & undefined are falsey values, and because we're using == we're basically saying false == false which should evaluate to true.
If we were using === it should indeed be false since we're comparing values and types as well.
| // - Check if num is either negative or odd using the logical OR operator. Log the result to the console. | ||
| // TODO: ADD YOUR CODE BELOW | ||
|
|
||
| console.log(num == "negative"|| num == "odd") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To check if the number is negative correctly:
num < 0
To check if the number is odd we use the mod operator:
num % 2 !== 0
or
num % 2 === 1
I finished the required tasks as needed based on the given instructions.