Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //var shouldnt be used
- //has global scope
- //let is new var
- //const is const
- //let and cosnt have block-level scope
- // const name = 'John';
- // const age = 30;
- // console.log(`My name is ${name} and I am ${age} years old`);
- // const s = 'Hello world';
- // console.log(s.split(' '));
- // const fruits = ['Apples', 'Strawberries', 'Oranges']
- // console.log(fruits.indexOf('oranges'))
- // //Object literals: key/value pairs. Not classes
- // const person = {
- // firstName: 'John',
- // lastName: 'Doe',
- // age: 30,
- // hobbies: ['music', 'gaming', 'sports'],
- // address: {
- // city: 'Skopje',
- // zipCode: 1000,
- // address: 'Partiznaski Odredi #12'
- // }
- // }
- // console.log(person)
- // const {address} = person
- // console.log(address)
- // person.address.country = 'Maceodnia'
- const todos = [
- {
- id: 1,
- text: 'Take out trash',
- isCompleted: true
- },
- {
- id: 2,
- text: 'Walk the dog',
- isCompleted: false
- },
- {
- id: 2,
- text: 'Shoot myself',
- isCompleted: false
- },
- ];
- // console.log(todos)
- //JSON - double quotes for everything, no single quotes, and variable names quoted
- // [
- // {
- // "id": 1,
- // "text": "Take out trash",
- // "isCompleted": true
- // },
- // {
- // "id": 2,
- // "text": "Walk the dog",
- // "isCompleted": false
- // },
- // {
- // "id": 2,
- // "text": "Shoot myself",
- // "isCompleted": false
- // }
- // ]
- // Convert array of object litterals to JSON format
- // const todoJSON = JSON.stringify(todos);
- // console.log(todoJSON)
- //For
- // for(let i = 0; i < todos.length; ++i){
- // console.log(todos[i])
- // }
- // for(let todo of todos){
- // console.log(todo)
- // }
- //High order Array methods - forEach, map, filter
- //forEach
- // todos.forEach(function(todo){
- // console.log(todo)
- // });
- //map
- // const todoText = todos.map(function(todo){
- // return todo.text;
- // });
- // console.log(todoText)
- // //mafilterp
- // const todoComplete = todos.filter(function(todo){
- // return todo.isCompleted;
- // }).map(function(todo){
- // return todo.text;
- // })
- // console.log(todoComplete)
- // const color = 'blue';
- // switch(color) {
- // case 'red':
- // console.log('color is red')
- // break
- // case 'blue':
- // console.log('color is blue')
- // break
- // default:
- // console.log('color is something other than red and blue')
- // break;
- // }
- function addNumbs(num1, num2){
- console.log(num1 + num2);
- }
- addNumbs(3, 4)
- //Arrow Functions
- const addFive = num => num+5;
- console.log(addFive(4))
- todos.forEach(todo => todo.user = 'Ivan')
- console.log(todos)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement