JS - Day 2
// Function without parameter and without return type
function add() {
console.log(9+9)
}
add()
// Function with parameter and without return type
function addB(x,y) {
console.log(x+y)
}
addB(10,12)
// Function with parameter and with return type
function addC(x,y){
return(x+y)
}
let q = addC(12,14)
console.log(q)
console.log(q+5)
console.log(q+q)
console.log(q-q)
// Data Types : number, boolean, string
let x2 = 23
console.log(typeof x2) // number // any +ve, -ve, fraction number is a number
let x3 = true
console.log(typeof x3) // boolean // any statement whose value or output is only true or false is a boolean
let x4 = "Ashish"
console.log(typeof x4) // string // any character written in single or double quote is considered as a string
// Comparison Operator // that compares LHS and RHS i.e. left hand side and right hand side
// < less than, > greater than, <= is less or equal, >= is greater or equal, != is not equal
// == is equal, === value equal & type equal, !== value not equal or type equal
// Value // this means only value is compared
console.log(5>8) // meaning - 5 greater than 8 // output: false
console.log(8<9) // meaning - 8 less than 9 // output: true
console.log(10==10) // meaning - 10 is equal to 10 // output: true
console.log(10!=10) // meaning - 10 is not equal to 10 // output: false
console.log(10<=11) // meaning - 10 is less than OR equal to 11 // output: true // because one statement is correct
console.log(10>=11) // meaning - 10 is greater than OR equal to 11 // output: false // because both statements are wrong
console.log(5=='5') // meaning - value of 5 is equal to value of 5 // output: true // but here type of RHS is string
console.log(7>=5) // meaning - LHS is greater than RHS OR equal to RHS // output: true // because one statement is correct
console.log(6<=6) // meaning - LHS is less than OR equal to RHS // output: true
// Value and Type // this means value and type both compared
console.log(7==='7') // meaning - LHS value is equal to RHS and LHS data type is equal to RHS data type // output: false // because data type is diff.// as LHS data type is number and RHS data type is string
console.log(1!==2) // meaning - LHS value is not equal to RHS or LHS data type is not equal RHS
// output: true // because one statement is true
console.log(1!=='2') // meaning - LHS value is not equal to RHS or LHS data type is not equal RHS
// output: true // because one statement is true
console.log(10!==10) // meaning - LHS value is not equal to RHS or LHS data type is not equal to RHS
// output: false // because both statements false
-blog by Ashish Naik
Comments
Post a Comment