Created
September 12, 2018 05:23
-
-
Save jaamaalxyz/188b93bbea88b7239ab9a11fb8a2c30d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// declare an array with const | |
const arr = [1, 2, 3]; | |
console.log(arr) // [1, 2, 3] | |
// try to re-decalre an array with the same name and cought an error | |
let arr = [2, 3, 4]; // SyntaxError: Identifier 'arr' has already been declared | |
// but you can change the value | |
arr.push(4); | |
console.log(arr); // [1, 2, 3, 4] | |
// declare an object | |
const myObj = { | |
firstName: 'Jamal', | |
lastName: 'Uddin' | |
}; | |
// can't re-declare any object with same name when used const | |
const myObj = { age: 23 }; // SyntaxError: Identifier 'myObj' has already been declared | |
// but you can change the key and values | |
myObj.age = 23; | |
console.log(myObj); // {firstName: "Jamal", lastName: "Uddin", age: 23} | |
myObj.message = () => `Hello! I am ${this.firstName} ${this.lastName}, I am ${this.age} years old young man! learning JavaScript & React.`; | |
console.log(myObj.message()); | |
// Hello! I am undefined undefined, I am undefined years old young man! learning JavaScript & React. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment