You are on page 1of 4

// var, let, const

// var in globaly scoped, better use let, const

// let can reassign values

// const is constant; use it unless you know you're going to reassign the value

// strings, numbers, boolean, null, undefined, symbol

// Concatenation

console.log('My name is ' + name + ' and I am ' + age + ' years old.');

// Template string

const hello = `My name is ${name} and I am ${age} years old.`;

console.log(hello);

/* multi

line comment*/

// For

for(let i = 0; i <= 10; i++) {

console.log(`For loop number: ${i}`)

for(let todo of todos) {

console.log(todo.text)

// While

let i = 0

while(i < 10) {

console.log(`While loop number: ${i}`)

i++
}

// forEach, map, filter

todos.forEach(function(todo) {

console.log(todo.text)

})

const todoText = todos.map(function(todo) {

return todo.text

})

console.log(todoText)

const todoCompleted = todos.filter(function(todo) {

return todo.isCompleted === true

}).map(function(todo) {

return todo.text

})

console.log(todoCompleted)

|| or

&& and

? then

: else ’red’ : ’blue’

// class {

class Person {

constructor(firstName, lastName, dob) {


this.firstName = firstName

this.lastName = lastName

this.dob = new Date(dob)

getBirthYear() {

return this.dob.getFullYear()

getFullName() {

return `${this.firstName} ${this.lastName}`

// Instantiate object

const person1 = new Person('John', 'Smith', '4-3-1987')

const person2 = new Person('Mary', 'Wilkes', '5-4-1993')

console.log(person1)

console.log(person2.getFullName())

const ul = document.querySelector('.items')

// ul.remove()

// ul.lastElementChild.remove()

ul.firstElementChild.textContent = 'Hello'

ul.children[1].innerText = 'Brad'

ul.lastElementChild.innerHTML = '<h1>Hello</h1>'

const btn = document.querySelector('.btn')


btn.style.background = 'red'

You might also like