Advertisement
samimwebdev

logical && ||, conditionals, loop introduction

May 26th, 2022
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //logical AND(&&) OR(||) operator
  2. //logical Not(!)
  3. //short circuit
  4. //if, else, else if
  5. //ternary
  6. //switch
  7.  
  8. //truthy and falsy value
  9. //Boolean (true , false)
  10. //truthy or falsy
  11.  
  12. //falsy value
  13. //false
  14. //0
  15. //''
  16. //undefined
  17. //null
  18. //NaN
  19.  
  20. //!(logical not)
  21. // console.log(!!false)
  22. // console.log(!!'')
  23. // console.log (Boolean(''))
  24.  
  25. //truthy (other than falsy value)
  26.  
  27. //if else if else
  28. // const age = 17
  29. // if(age >= 18){
  30. //     console.log('you can vote')
  31. // }else{
  32. //     console.log('you can not vote')
  33. // }
  34.  
  35. //alternative (ternary)
  36. // const result = age >= 18 ?  'you can vote' :  'you can not vote'
  37. // console.log(result)
  38.  
  39. // age === 18 = true
  40. //18 === true
  41.  
  42. // console.log(age >= 18 && age)
  43. // switch(true){
  44. //     case age >= 18:
  45. //     console.log('you can vote')
  46. //     break
  47. //     case 19:
  48. //     console.log('you are 19')
  49. //     break
  50. //     default:
  51. //     console.log('unknown')
  52. // }
  53.  
  54.  
  55. //logical AND(&&) OR(||) operator
  56.  
  57. //&& - result true when every part is true
  58. //otherwise false
  59. //short circuit
  60. // console.log(true && true && true)
  61. // console.log(true && false && true) //short circuit
  62. // console.log(true && false && false) //short circuit
  63.  
  64. // const showMessage = false
  65. // console.log(showMessage && 'Hello world')
  66.  
  67.  
  68. //logical OR(||)
  69. // if any part is true result will be true
  70. //otherwise false
  71. // console.log(false || false || true)  
  72. // console.log(false || false || false)  
  73. // console.log(false || true || false) //short circuit
  74. // console.log(true || true || true)//short circuit
  75.  
  76. // const showMessage = false
  77. // console.log(showMessage || 'Hello world')
  78. // console.log(showMessage || '')
  79.  
  80.  
  81.  
  82. //loop -repetition
  83. // for(init; condition; incrementordecrement+){
  84. //     //output
  85. // }
  86.  
  87.  
  88. //for loop
  89. // for(let i = 0; i < 10; i++ ){
  90. //     console.log(`Hello world ${i + 1} ${i + 1 < 2 ? 'time': 'times'}`)
  91. // }
  92.  
  93. //while loop
  94. // let i = 0
  95. // while(i < 10){
  96. //     console.log(`Hello world ${i + 1} ${i + 1 < 2 ? 'time': 'times'}`)
  97. //     i++
  98. // }
  99.  
  100.  
  101.  
  102. //10 times
  103. // console.log('Hello world')
  104. // console.log('Hello world')
  105. // console.log('Hello world')
  106. // console.log('Hello world')
  107. // console.log('Hello world')
  108. // console.log('Hello world')
  109. // console.log('Hello world')
  110. // console.log('Hello world')
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement