Day-7: Logical operators, parseInt method, & I learned one of the looping method(while):
1. Logical AND (&&) Operator: The logical AND (&&) operator checks whether both operands are true. If both are true, the result is true. If any one or both operands are false, the result is false. // Check if both conditions are true let age = 20; let idProof = true; // Logical AND checks both conditions if (age >= 18 && idProof) { console.log("Allowed"); } else { console.log("Not Allowed"); } Output: Allowed 2. Logical OR (||) Operator: The logical OR (||) operator checks whether at least one of the operands is true. If either operand is true, the result is true. If both operands are false, the result is false. // Check if at least one condition is true let age = 16; let hasGuardian = true; // Logical OR checks if either condition is true if (age >= 18 || hasGuardian) { console.log("Allowed"); } else { console.log("Not Allowed"); } Output: Allowed JavaScript Number parseInt() Method: TheparseInt method parses a value as a string and returns the first integer. It accepts a string argument and optional radix parameter, defining the numeral system base. This method is commonly used for converting string representations of numbers into integers. Example: The method takes two parameters: the string to be parsed and the radix (optional, default is 10). 2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal. Syntax: parseInt(Value, radix); Parameters: Value: This parameter contains a string that is converted to an integer. radix: This parameter represents the radix or base to be used and it is optional. [Reference - geeksforgeeks] looping statements in JavaScript: JavaScript provides several ways to execute a block of code repeatedly. These are called looping statements. while loop: Executes a block of code as long as a specified condition is true. Syntax: while (condition) { // code to execute } Example: let i = 0; while (i < 5) { console.log(i); // Output: 0, 1, 2, 3, 4 i++; }

1. Logical AND (&&) Operator:
The logical AND (&&) operator checks whether both operands are true. If both are true, the result is true. If any one or both operands are false, the result is false.
// Check if both conditions are true
let age = 20;
let idProof = true;
// Logical AND checks both conditions
if (age >= 18 && idProof) {
console.log("Allowed");
} else {
console.log("Not Allowed");
}
Output:
Allowed
2. Logical OR (||) Operator:
The logical OR (||) operator checks whether at least one of the operands is true. If either operand is true, the result is true. If both operands are false, the result is false.
// Check if at least one condition is true
let age = 16;
let hasGuardian = true;
// Logical OR checks if either condition is true
if (age >= 18 || hasGuardian) {
console.log("Allowed");
} else {
console.log("Not Allowed");
}
Output:
Allowed
JavaScript Number parseInt() Method:
TheparseInt method parses a value as a string and returns the first integer. It accepts a string argument and optional radix parameter, defining the numeral system base. This method is commonly used for converting string representations of numbers into integers.
Example:
The method takes two parameters: the string to be parsed and the radix (optional, default is 10).
2 = binary, 8 = octal, 10 = decimal, 16 = hexadecimal.
Syntax:
parseInt(Value, radix);
Parameters:
- Value: This parameter contains a string that is converted to an integer.
- radix: This parameter represents the radix or base to be used and it is optional.
[Reference - geeksforgeeks]
looping statements in JavaScript:
JavaScript provides several ways to execute a block of code repeatedly. These are called looping statements.
while loop:
- Executes a block of code as long as a specified condition is true.
- Syntax: while (condition) { // code to execute }
- Example:
let i = 0;
while (i < 5) {
console.log(i); // Output: 0, 1, 2, 3, 4
i++;
}