Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. //var shouldnt be used
  2. //has global scope
  3.  
  4.  
  5. //let is new var
  6. //const is const
  7. //let and cosnt have block-level scope
  8.  
  9. // const name = 'John';
  10. // const age = 30;
  11.  
  12. // console.log(`My name is ${name} and I am ${age} years old`);
  13.  
  14. // const s = 'Hello world';
  15.  
  16. // console.log(s.split(' '));
  17.  
  18. // const fruits = ['Apples', 'Strawberries', 'Oranges']
  19.  
  20. // console.log(fruits.indexOf('oranges'))
  21.  
  22. // //Object literals: key/value pairs. Not classes
  23.  
  24. // const person = {
  25.  
  26. // firstName: 'John',
  27. // lastName: 'Doe',
  28. // age: 30,
  29. // hobbies: ['music', 'gaming', 'sports'],
  30. // address: {
  31.  
  32. // city: 'Skopje',
  33. // zipCode: 1000,
  34. // address: 'Partiznaski Odredi #12'
  35. // }
  36. // }
  37.  
  38. // console.log(person)
  39.  
  40. // const {address} = person
  41.  
  42. // console.log(address)
  43.  
  44. // person.address.country = 'Maceodnia'
  45.  
  46. const todos = [
  47.  
  48. {
  49. id: 1,
  50. text: 'Take out trash',
  51. isCompleted: true
  52. },
  53. {
  54. id: 2,
  55. text: 'Walk the dog',
  56. isCompleted: false
  57. },
  58. {
  59. id: 2,
  60. text: 'Shoot myself',
  61. isCompleted: false
  62. },
  63. ];
  64.  
  65. // console.log(todos)
  66.  
  67. //JSON - double quotes for everything, no single quotes, and variable names quoted
  68. // [
  69. // {
  70. // "id": 1,
  71. // "text": "Take out trash",
  72. // "isCompleted": true
  73. // },
  74. // {
  75. // "id": 2,
  76. // "text": "Walk the dog",
  77. // "isCompleted": false
  78. // },
  79. // {
  80. // "id": 2,
  81. // "text": "Shoot myself",
  82. // "isCompleted": false
  83. // }
  84. // ]
  85.  
  86. // Convert array of object litterals to JSON format
  87.  
  88. // const todoJSON = JSON.stringify(todos);
  89. // console.log(todoJSON)
  90.  
  91. //For
  92. // for(let i = 0; i < todos.length; ++i){
  93.  
  94. // console.log(todos[i])
  95. // }
  96.  
  97. // for(let todo of todos){
  98.  
  99. // console.log(todo)
  100. // }
  101.  
  102. //High order Array methods - forEach, map, filter
  103.  
  104. //forEach
  105. // todos.forEach(function(todo){
  106.  
  107. // console.log(todo)
  108. // });
  109.  
  110. //map
  111. // const todoText = todos.map(function(todo){
  112.  
  113. // return todo.text;
  114. // });
  115.  
  116. // console.log(todoText)
  117.  
  118. // //mafilterp
  119. // const todoComplete = todos.filter(function(todo){
  120.  
  121. // return todo.isCompleted;
  122. // }).map(function(todo){
  123.  
  124. // return todo.text;
  125. // })
  126.  
  127. // console.log(todoComplete)
  128.  
  129. // const color = 'blue';
  130.  
  131. // switch(color) {
  132.  
  133. // case 'red':
  134. // console.log('color is red')
  135. // break
  136. // case 'blue':
  137. // console.log('color is blue')
  138. // break
  139. // default:
  140. // console.log('color is something other than red and blue')
  141. // break;
  142. // }
  143.  
  144. function addNumbs(num1, num2){
  145.  
  146. console.log(num1 + num2);
  147. }
  148.  
  149. addNumbs(3, 4)
  150.  
  151. //Arrow Functions
  152.  
  153. const addFive = num => num+5;
  154.  
  155. console.log(addFive(4))
  156.  
  157. todos.forEach(todo => todo.user = 'Ivan')
  158.  
  159. console.log(todos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement