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
var someValue = "Hello, world!"; | |
console.log("Type of someValue:", typeof someValue); | |
// Logs: Type of someValue: string | |
someValue = 2018; | |
console.log("Type of someValue:", typeof someValue); | |
// Logs: Type of someValue: number | |
someValue = {}; | |
console.log("Type of someValue:", typeof someValue); |
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("\"string\" type:", typeof "string"); // Logs: "string" type: string | |
console.log("7 type:", typeof 7); // Logs: 7 type is: number | |
console.log("7.5 type:", typeof 7.5); // Logs: 7.5 type is: number | |
console.log("true type:", typeof true); // Logs: true type: boolean | |
console.log("undefined type:", typeof undefined); // Logs: undefined type: 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
function isPalindrome(str) { | |
var reverse = str.split("").reverse().join(""); | |
return str === reverse; | |
} | |
function getCharCounts(chars) { | |
var charCounts = {}; | |
for (var i = 0, charLen = chars.length; i < charLen; i += 1) { | |
if (charCounts[chars[i]]) { | |
charCounts[chars[i]] += 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
function Robot(name, job) { | |
this.name = name; | |
this.job = job; | |
} | |
Robot.prototype.introduce = function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}; | |
var bender = new Robot("Bender", "bending"); |
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 makeCalendar(name) { | |
var calendar = { | |
owner: name, | |
events: [], | |
}; | |
return { | |
addEvent: function(event, dateString) { | |
var eventInfo = { | |
event: event, |
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 schedulerMaker(name) { | |
return function(event) { | |
return function() { | |
console.log(event + " with " + name + "."); | |
}; | |
}; | |
} | |
var adaScheduler = schedulerMaker("Ada"); | |
var coffeeWithAda = adaScheduler("Coffee"); |
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 makeEventDescriber(event, date) { | |
return function() { | |
console.log(date + ": " + event); | |
}; | |
} | |
var coffeeWithAda = makeEventDescriber("Coffee with Ada.", "8/1/2018"); | |
var partyAtCharles = makeEventDescriber("Party at Charles' house.", "8/4/2018"); | |
coffeeWithAda(); // Logs: "8/1/2018: Coffee with Ada." |
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
var event = "Coffee with Ada."; | |
function describeEvent() { | |
console.log(event); | |
} | |
function calendar() { | |
var event = "Party at Charles' house."; | |
describeEvent(); |
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
var event = "Coffee with Ada."; | |
function calendar() { | |
var event = "Party at Charles' house."; | |
console.log(event); | |
} | |
calendar(); // Logs: "Party at Charles' house." |
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 Robot(name, job) { | |
this.name = name; | |
this.job = job; | |
this.introduce = function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}; | |
} | |
function AI(name, job, intelligenceLevel) { |