Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //falsy value
- //false
- //0
- //''
- //NaN
- //undefined
- //null
- //check the value is truthy or falsy
- // console.log(Boolean(NaN))
- console.log(!false)
- console.log(!!'hello')
- console.log(!!0)
- console.log(!!undefined)
- //(&&)if all part(operands) is true then result will be true
- //otherwise false
- const val1 = true && true && true
- const val3 = true && true && '' && false
- const val4 = false && false
- //(||)if any part (operand) is true then result will be true
- //otherwise false
- const val2 = false || 'Hello' || true //(short circuit)
- const val5 = false || false || 'Hi' //No short circuit
- //&&
- console.log(val1)
- console.log(val3)
- console.log(val4)
- // ||
- console.log(val2)
- console.log(val5)
- // const age = 10
- //coercion(boolean)
- // if(true){
- // console.log('...')
- // }else{
- // console.log(age)
- // }
- //condition ? true : false //ternary operator
- // age <= 10 ? console.log('Baby'):console.log('adult')
- // if (age <= 10) {
- // console.log('Baby')
- // } else if (age <= 13) {
- // console.log('Growing to adult')
- // } else {
- // console.log('adult')
- // }
- // const age = 10
- // switch (age) {
- // case 10:
- // console.log('Age is', 10)
- // break
- // case 11:
- // console.log('Age is', 10)
- // break
- // default:
- // console.log('Unknown Age')
- // }
- // console.log(true && false && 'someVal')
- // let myAge = 18
- // switch (myAge) {
- // case myAge <= 10 && myAge:
- // console.log('you are out of range!')
- // break
- // case myAge <= 15 && myAge:
- // console.log('stay home under your mom supervision')
- // break
- // case myAge < 18 && myAge:
- // console.log('try to gain knowledge from outside of home')
- // break
- // case (myAge >= 18 && myAge <= 20) && myAge:
- // console.log('prepare to cast vote')
- // break
- // default:
- // console.log('cast you vote')
- // }
- //for , while
- //loop - repetition
- // for (let i = 0; i < 10; i++) {
- // console.log('I Love Bangladesh')
- // console.log(i)
- // }
- // let i = 1
- // while(i <= 10){
- // console.log('I Love Bangladesh')
- // i++
- // }
- //function
- // function getAvg(num1, num2) {
- // //sum
- // const sum = num1 + num2
- // //average
- // const average = sum / 2
- // console.log(average)
- // }
- // getAvg(10, 20)
- // getAvg(20, 20)
- // //sum
- // const sum2 = 20 + 20
- // //average
- // const average2 = sum2 / 2
- // console.log(average2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement