Skip to content

Latest commit

 

History

History
169 lines (165 loc) · 2.28 KB

6. Booleans and Boolean Expression.md

File metadata and controls

169 lines (165 loc) · 2.28 KB

6. Booleans and Boolean Expression

JavaScript Booleans

const value1 = true;
const value2 = false;

console.log(value1);
console.log(value2);

Output

true
false

To know the type of data

const value1 = true;
const value2 = false;
console.log(value1);
console.log(value2);
console.log(typeof(value1));
console.log(typeof(value2));

Output

true
false
boolean
boolean

true and false shouldn't be used inside quotes

const value1 = "true";
const value2 = "false";
console.log(value1);
console.log(value2);
console.log(typeof(value1));
console.log(typeof(value2));

Output

true
false
string
string

JavaScript is a case-sensitive

const value1 = True;
const value2 = False;
console.log(value1);
console.log(value2);

Output

ReferenceError: Can't find variable: True

Comparison Operators

Greater Than Operators

console.log(8  > 5);

Output

true

Less Than Operator

console.log(3 < 5);

Output

true

Greater Than or Equal Operator

console.log(5 >= 5);

Output

true

Equal to Operator

console.log(5 == 5);

Output

true

Not Equal to Operator

console.log(5 != 5);

Output

false

Strict equal to Operator

console.log("5" === 5);

Output

false

Comparison Between Variables

const number1 = 5;
const number2 = 9;

const result = number1 < number2;
console.log(result);

Output

true

JavaScript Logical Operators

JavaScript AND Operator

const age = 18;
const height = 5.5;
let result = age >= 18 && height > 5;
console.log(result);

Output

true

JavaScript OR Operator

let age = 18;
let height = 5.5;
let result = age >= 18 || height < 5;
console.log(result);

Output

true

JavaScript NOT Operator

const height = 5.5;
const result = height < 6;
console.log(!result);

Output

false

Programmiz Quiz

Q. Which of the following code returns true?

  1. 5 == -5
  2. 5 == '5'
  3. 5 === '5'
  4. 5 === -5
Answer: 2