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 pokemon = { | |
experience: 0, | |
fight: function() { | |
console.log(this.experience); | |
this.experience += Math.floor(Math.random() * 10) + 1; | |
} | |
}; |
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 pokemon = { | |
experience: 0, | |
fight: () => { | |
this.experience += Math.floor(Math.random() * 10) + 1; | |
} | |
}; | |
pokemon.fight(); | |
console.log(pokemon.experience); | |
// Output: 0 |
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 logUser = ({ name, pass }) => | |
`Logging user ${name} with password: ${pass}`; | |
const user = { name: "Nya", pass: "secretpassw0rd" }; | |
console.log(logUser(user)); | |
// Output: Logging user Nya with password: secretpassw0rd |
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 choosePokemon = ( | |
firstPokemon = "Charmander", | |
secondPokemon = "Bulbasaur" | |
) => `I choose ${firstPokemon} and ${secondPokemon}`; | |
// Calling function without parameters | |
console.log(choosePokemon()); | |
// Output: I choose Charmander and Bulbasaur |
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
function sayHello(name) { | |
return `Hello ${name}!`; | |
} | |
console.log(sayHello.prototype); | |
// Output: {...} | |
const sayHelloArrow = name => `Hello ${name}`; | |
console.log(sayHelloArrow.prototype); | |
// Output: undefined |
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 choosePokemonArrow = (firstPokemon, secondPokemon) => | |
`I choose ${firstPokemon} and ${secondPokemon}!`; | |
console.log(choosePokemonArrow("Squirtle", "Bulbasaur")); |
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 sayHello = () => "Hello!"; | |
console.log(sayHello()); |
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
function choosePokemon(firstPokemon, secondPokemon) { | |
return `I choose ${firstPokemon} and ${secondPokemon}!`; | |
} | |
console.log(choosePokemon("Charmander", "Squirtle")); | |
// Output: I choose Charmander and Squirtle! |
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 User = () => {}; | |
const user = new User(); | |
// Output: Error: User is not a constructor |
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 choosePokemonArrow2 = pokemon => { | |
console.log("Logging"); | |
return `I choose you ${pokemon}!`; | |
}; | |
console.log(choosePokemonArrow2("Bulbasaur")); | |
/* Output: | |
Logging | |
I choose you Bulbasaur! | |
*/ |