Podcast
Questions and Answers
What is the output of the following code snippet: console.log(5 < 10)?
What is the output of the following code snippet: console.log(5 < 10)?
What does the following code snippet output: console.log(3 > 5 || 0)?
What does the following code snippet output: console.log(3 > 5 || 0)?
In JavaScript, what would be the result of console.log(5 === '5')?
In JavaScript, what would be the result of console.log(5 === '5')?
What is the final value of a after executing the code: let a = 5; a++; ++a; a--?
What is the final value of a after executing the code: let a = 5; a++; ++a; a--?
Signup and view all the answers
What is the output of console.log(!(5 > 3))?
What is the output of console.log(!(5 > 3))?
Signup and view all the answers
What would be the result of console.log(1 == true)?
What would be the result of console.log(1 == true)?
Signup and view all the answers
Given a = 2, what does console.log(a++ - --a) output?
Given a = 2, what does console.log(a++ - --a) output?
Signup and view all the answers
What will be the output of console.log((4 + 2) * 3)?
What will be the output of console.log((4 + 2) * 3)?
Signup and view all the answers
For console.log(!(0 && true)), what would be the output?
For console.log(!(0 && true)), what would be the output?
Signup and view all the answers
If let x = 5, what will be the result of console.log(x += x - x++)?
If let x = 5, what will be the result of console.log(x += x - x++)?
Signup and view all the answers
Study Notes
Prefix Increment and Decrement Operators
- The operator is placed before the variable, and the value of the variable is incremented or decremented before it is used.
- Example:
let a = 10; console.log(++a); // 11
andlet a = 10; console.log(--a); // 9
Postfix Increment and Decrement Operators
- The operator is placed after the variable, and the value of the variable is used before it is incremented or decremented.
- Example:
let a = 10; console.log(a++); // 10
andlet a = 10; console.log(a--); // 10
Comparison Operators
- Comparison operators compare two values and return a Boolean value: either
true
orfalse
. - They are useful in decision-making and loop programs in JavaScript.
Arithmetic Operators
- Addition:
let sum = 5 + 3; console.log(sum); // 8
- Subtraction:
let difference = 10 - 4; console.log(difference); // 6
- Multiplication:
let product = 2 * 6; console.log(product); // 12
- Division:
let quotient = 15 / 3; console.log(quotient); // 5
- Remainder (Modulus):
let remainder = 17 % 4; console.log(remainder); // 1
- Exponentiation:
let result = 2 ** 4; console.log(result); // 16
Assignment Operator
- Assignment operators are used to assign values to variables.
- The
=
sign is used for assignment. - Examples:
- Addition assignment:
x += 3;
- Subtraction assignment:
x -= 2;
- Multiplication assignment:
x *= 4;
- Division assignment:
x /= 3;
- Remainder (Modulus) assignment:
x %= 5;
- Exponentiation assignment:
x **= 2;
- Addition assignment:
Logical Operators
- Logical OR:
true || true; // true
,true || false; // true
,false || true; // true
,false || false; // false
- Logical NOT:
!
converts the operator to Boolean and returns a flipped value. - Example:
let Yes = true; let No = false; console.log(!Yes); // false
,console.log(!No); // true
Operator Precedence
- Operator precedence determines the order in which operators are parsed concerning each other.
- Example:
let result = 2 + 3 * 4; console.log(result); // 14
- The order of operations is determined by the operator's precedence value.
Operator Associativity
- Operator associativity defines the order in which operators of the same precedence are evaluated.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Learn about the prefix and postfix increment and decrement operators in JavaScript. Understand how these operators behave before and after the variable. Practice examples to see the effects of using these operators.