Created
February 1, 2019 10:05
-
-
Save fleepgeek/f8beabdab0d536040c2302bbcb4dfc85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// var btnShow = document.querySelector(".btn-show"); | |
// var box = document.querySelector(".box"); | |
// btnShow.addEventListener("click", () => { | |
// box.classList.toggle("show"); | |
// }); | |
// var allows reassignment which could be harmful if unintentionally did it. | |
// var name = "John"; | |
// var name = "Mike"; | |
// console.log(name); | |
// Hoisting is the movement of variales and functions to the top of | |
// its scope before the code is executed | |
// console.log(city); | |
// var city = "Lagos"; | |
// var variables are hoisted to the top of the scope and initialized to undefined | |
// The above code is interpreted as: | |
/* | |
var city | |
console.log(city); // undefined | |
var city = "Lagos"; | |
*/ | |
// let and const variables are hoisted to the top but are not initialized | |
// so calling them before declaring them, you'll get a Reference error | |
// let name = "John"; | |
// let name = "Mike"; Won't work. let can't be redeclared | |
// console.log(name); | |
// let and const are block scoped while var is global scoped | |
// const PI = 3.142; | |
// PI = 22; This won't work because constant variables can't be reassigned | |
// console.log(PI); | |
// let person = { | |
// fullName: "John Mike", | |
// age: 22, | |
// school: { | |
// name: "Salvation Academy", | |
// address: "No 28 Salvation Str, Lagos" | |
// } | |
// } | |
// let { fullName, school, age } = person; | |
// console.log(name); | |
// let { name, address } = person.school; | |
// let grades = [40, 34, 75, 55, 65]; | |
// let [a, b, c, ...rest] = grades; | |
// console.log(c, rest); | |
// let moreGrades = [...grades, 90, 40]; | |
// console.log(moreGrades); | |
// class Student { | |
// constructor(fName, lName, age) { | |
// this.fName = fName; | |
// this.lName = lName; | |
// this.age = age; | |
// } | |
// fullName() { | |
// return this.fName + " " + this.lName; | |
// } | |
// } | |
// var student1 = new Student("John", "Olu", 29); | |
// var student2 = new Student("Mike", "Obi", 19); | |
// console.log(student1.fullName()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment