Advertisement
samimwebdev

Code sample -Logical AND , OR operator, conditional, switch, loop, function(4)

Dec 8th, 2021 (edited)
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //falsy value
  2. //false
  3. //0
  4. //''
  5. //NaN
  6. //undefined
  7. //null
  8.  
  9. //check the value is truthy or falsy
  10. // console.log(Boolean(NaN))
  11. console.log(!false)
  12. console.log(!!'hello')
  13. console.log(!!0)
  14. console.log(!!undefined)
  15.  
  16. //(&&)if all part(operands) is true then result will be true
  17. //otherwise false
  18. const val1 = true && true && true
  19. const val3 = true && true && '' && false
  20. const val4 = false && false
  21.  
  22. //(||)if any part (operand) is true then result will be true
  23. //otherwise false
  24. const val2 = false || 'Hello' || true //(short circuit)
  25. const val5 = false || false || 'Hi' //No short circuit
  26.  
  27. //&&
  28. console.log(val1)
  29. console.log(val3)
  30. console.log(val4)
  31.  
  32. // ||
  33. console.log(val2)
  34. console.log(val5)
  35.  
  36. // const age = 10
  37.  
  38. //coercion(boolean)
  39. // if(true){
  40. //   console.log('...')
  41. // }else{
  42. //   console.log(age)
  43. // }
  44.  
  45. //condition ? true : false //ternary operator
  46. // age <= 10 ? console.log('Baby'):console.log('adult')
  47.  
  48. // if (age <= 10) {
  49. //   console.log('Baby')
  50. // } else if (age <= 13) {
  51. //   console.log('Growing to adult')
  52. // } else {
  53. //   console.log('adult')
  54. // }
  55.  
  56. // const age = 10
  57.  
  58. // switch (age) {
  59. //   case 10:
  60. //     console.log('Age is', 10)
  61. //     break
  62. //   case 11:
  63. //     console.log('Age is', 10)
  64. //     break
  65. //   default:
  66. //     console.log('Unknown Age')
  67. // }
  68.  
  69. // console.log(true && false && 'someVal')
  70.  
  71. // let myAge = 18
  72.  
  73. // switch (myAge) {
  74. //   case myAge <= 10 && myAge:
  75. //     console.log('you are out of range!')
  76. //     break
  77.  
  78. //   case myAge <= 15 && myAge:
  79. //     console.log('stay home under your mom supervision')
  80. //     break
  81.  
  82. //   case myAge < 18 && myAge:
  83. //     console.log('try to gain knowledge from outside of home')
  84. //     break
  85. //   case (myAge >= 18 && myAge <= 20) && myAge:
  86. //     console.log('prepare to cast vote')
  87. //     break
  88. //   default:
  89. //     console.log('cast you vote')
  90. // }
  91.  
  92. //for , while
  93. //loop - repetition
  94.  
  95. // for (let i = 0; i < 10; i++) {
  96. //   console.log('I Love Bangladesh')
  97. //   console.log(i)
  98. // }
  99.  
  100. // let i = 1
  101.  
  102. // while(i <= 10){
  103. //   console.log('I Love Bangladesh')
  104. //   i++
  105. // }
  106.  
  107.  
  108.  
  109. //function
  110. // function getAvg(num1, num2) {
  111. //   //sum
  112. //   const sum = num1 + num2
  113. //   //average
  114. //   const average = sum / 2
  115. //   console.log(average)
  116. // }
  117.  
  118. // getAvg(10, 20)
  119. // getAvg(20, 20)
  120.  
  121. // //sum
  122. // const sum2 = 20 + 20
  123. // //average
  124. // const average2 = sum2 / 2
  125. // console.log(average2)
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement