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
//immediately prints the value 'welcome to the jungle' | |
(function(){ | |
return "Welcome to the jungle!"; | |
})(); |
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
//This variable holds/stores a function that prints 'welcome to the jungle' | |
const welcomeMessageVariable = function (){ | |
return "Welcome to the jungle!"; | |
}; | |
//we will invoke our first variable here below | |
welcomeMessageVariable(); // Welcome to the jungle! | |
//This second variable holds/stores the value 'welcome to the jungle' |
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 greetingMessageIIFE = (function(name,message){ | |
let headline = `Lets create some IIFE's`; | |
return `${headline} | |
Hello ${name},${message}` | |
})('Neo',"Welcome to the Matrix!"); | |
//Lets create some IIFE's | |
//Hello Neo,Welcome to the Matrix! | |
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
//This function is 'impure' and is not re-usable | |
function addNumbers(){ | |
let num1 = 100; | |
let num2 = 1; | |
return num1 + num2; | |
} | |
addNumbers();//will always return 101 |
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
//lets define an object called book | |
const book = {}; | |
//lets add two properties to our book object | |
book.name = "Eloquent JavaScript: A Modern Introduction to Programming"; | |
book.author = "Marijn Haverbeke" | |
//lets define a method to get the book details | |
book.getBookDetails = function (){ | |
return "The book " + this.name + " was written by " + this.author; |
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
//define Book as an object constructor function | |
function Book(name,author) { | |
this.name = name; | |
this.author = author; | |
this.getBookDetails = function (){ | |
return "The book " + this.name + " was written by " + this.author; | |
} | |
} | |
//add some new books |
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
//define Book as an object constructor function | |
function Book(name,author) { | |
this.name = name; | |
this.author = author; | |
} | |
//add getBookDetails method to object prototype | |
Book.prototype.getBookDetails = function (){ | |
return `The book ${this.name} was written by ${this.author}`; | |
} |
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
//define Book as an object constructor function | |
class Book { | |
constructor(name,author,price){ | |
this.name = name; | |
this.author = author; | |
this.price = price; | |
} | |
getBookCost(){ | |
return `The book ${this.name} was written by ${this.author} and costs $${this.price}`; | |
} |
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 movie = { | |
name : "The Godfather", | |
year : 1972, | |
director: 'Francis Ford Coppola', | |
imdb_Rating: 9.2, | |
get movieDetails(){ | |
return ` | |
The movie : '${this.name}' was directed by ${this.director} and released in the year ${this.year}. | |
It has a very high IMDB Rating of ${this.imdb_Rating} / 10. | |
` |
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 movie = { | |
name : "The Godfather", | |
year : 1972, | |
director: 'Francis Ford Coppola', | |
imdb_Rating: 9.2, | |
set actors(name) { | |
this.cast.push(name); | |
}, | |
cast: [], | |
get movieDetails(){ |