Skip to content

Conversation

@JaeMaaroufi
Copy link

I finished the required tasks as needed based on the given instructions.

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

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

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
Copy link

@AlhassanAli01 AlhassanAli01 Feb 9, 2024

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

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

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

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")
Copy link

@AlhassanAli01 AlhassanAli01 Feb 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants