Advertisement
samimwebdev

class-4-logic ternary loop

Feb 20th, 2022
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // let num = 10
  2. //increment
  3. // num = num + 1
  4. // num += 1
  5. // num++
  6.  
  7. // // decrement
  8. // num = num - 1
  9. // num -= 1
  10. // num--
  11.  
  12. // console.log(num++)
  13. // console.log(num)
  14. // console.log(++num)
  15. // console.log(num)
  16.  
  17. //falsy values
  18. //false
  19. //0
  20. //undefined
  21. //NaN
  22. //''
  23.  
  24. //truthy values
  25. //other than falsy values
  26.  
  27. //how to check truthy or falsy values
  28. // console.log(!!'')
  29. // console.log(!!NaN)
  30. // console.log(!!false)
  31. // console.log(!!18)
  32.  
  33. // const age = 18
  34.  
  35. // if (age === 18) {
  36. //   console.log('you can vote')
  37. // } else {
  38. //   console.log("you can't vote")
  39. // }
  40.  
  41. //logical AND(&&)
  42. // const result = age === 19 && 'you can vote'
  43. // console.log(result)
  44.  
  45. //ternary operator
  46. // age === 18 ? console.log('you can vote') : console.log('you can\'t vote')
  47.  
  48. // const age = 20
  49. // // console.log(age >= 18 && age)
  50. // //multiple if else if(use switch)
  51. // switch (age) {
  52. //   case age >= 18 && age <= 21 && age:
  53. //     console.log('you can vote')
  54. //     break
  55. //   case 15:
  56. //     console.log("you can't vote")
  57. //     break
  58. //   default:
  59. //     console.log('You are of unknown age')
  60. // }
  61.  
  62. //loop (repetition)
  63. //for,while
  64.  
  65. // let arr = ['a', 'b', 'c', 'd']
  66.  
  67.  
  68. // arr[0]
  69. // arr[1]
  70. //simple for loop
  71. // for (let i = 0; i < arr.length; i++) {
  72. //   console.log(i)
  73. //  console.log(arr[i])
  74.  
  75. // }
  76. //for of loop
  77. // for(let elm of arr){
  78. //   console.log(elm)
  79. // }
  80.  
  81. //while loop
  82. // let i = 0
  83. // while (i < arr.length) {
  84. //   console.log(arr[i])
  85. //   i++
  86. // }
  87.  
  88. //break and continue
  89. // for (let i = 0; i < 10; i++) {
  90.  
  91. //   if(i === 7){
  92. //     break
  93. //   }
  94. //   console.log(i)
  95. //   let number = i + 1
  96. //   console.log(`we love bangladesh ${number} ${number >= 1 ? 'times' : 'time'}`)
  97. // }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement