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
| const wittyAI = 'I am \'not\' sentient.' | |
| const wittyReply = 'No, you\'re definitely not "sentient."' | |
| console.log(wittyAI,wittyReply) |
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
| const getEmail = username => `${username}@gmail.com` | |
| function getUser (username) { | |
| const email = getEmail(username) | |
| return { | |
| username: username, | |
| email: email | |
| } | |
| } | |
| console.log(getUser("MrRoboto")) // Object { username: "MrRoboto", email: "[email protected]" } |
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
| const getEmail = username => `${username}@gmail.com` | |
| function getUser (username) { | |
| const email = getEmail(username) | |
| return { | |
| username, | |
| } | |
| } | |
| console.log(getUser("MrRoboto")) // Object { username: "MrRoboto", email: "[email protected]" } |
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
| const hello = { world: function() { | |
| console.log('Hello World!') | |
| }} | |
| hello.world() // Hello World! | |
| const helloAgain = { world() { | |
| console.log('Hello World!') | |
| }} | |
| helloAgain.world() // Hello World! |
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
| const actions = { | |
| step: 0, | |
| printCount() { | |
| console.log(this.step) | |
| }, | |
| takeStep() { | |
| this.step++ | |
| } | |
| } | |
| actions.takeStep() |
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
| const actions = { | |
| step: 0, | |
| printCount: function () { | |
| console.log(this.step) | |
| }, | |
| takeStep: function () { | |
| this.step++ | |
| } | |
| } | |
| actions.takeStep() |
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
| [name, age, gender] = ["Derek","30","Male"] | |
| const wordyObject = { | |
| name: name, | |
| age: age, | |
| gender: gender | |
| } | |
| const conciseObject = { | |
| name, | |
| age, | |
| gender |
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
| console.log(cheese) // ReferenceError: can't access lexical declaration `cheese' before initialization | |
| let cheese = "Gouda" |
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
| let [profit, costs] = [120000, 100000] // It was a good month | |
| // Employee bonus structure: $1000 if >10% profit, $100 if not | |
| let employeeBonus = (profit/costs > 1.10) ? 1000 : 100 | |
| console.log("$"+employeeBonus) // $1000 |
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
| employeeBonus = profit/costs > 1.10 ? 1000 : 100 |