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
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
int myInt = 8; | |
double myDecimal = 8.5; | |
string myString = "electron"; |
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
my_int = 8 | |
my_decimal = 8.5 | |
my_string = "electron" | |
puts "My int is: #{my_int}" | |
puts "My float is: #{my_decimal}" | |
puts "My string is: #{my_string}" |
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 DinoError(message) { | |
this.name = "DinoError"; | |
this.message = message; | |
} | |
DinoError.prototype = new Error(); | |
function cloneDinosaur(name, type) { | |
var validTypes = ["Apatosaurus", "Dilophosaurus", "Tyrannosaurus Rex", "Stegosaurus"]; | |
try { |
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 cloneDinosaur(name) { | |
try { | |
var myDinosaur = { | |
name: name, | |
dangerMessage: name.toUpperCase() + " IS COMING!!!", | |
}; | |
return myDinosaur; | |
} catch (e) { | |
console.log(e.name + ": " + e.message); |
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 dinoError = new Error("Oh no! A dino error!"); | |
dinoError.name = "DinoError"; | |
console.log("dinoError name: ", dinoError.name); | |
// Logs: dinoError name: DinoError | |
console.log("dinoError message: ", dinoError.message); | |
// Logs: dinoError message: Oh no! A dino error! |
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("My favorite dinasaur is " + theropod); | |
// ReferenceError: theropod is not defined | |
var sauropod = "apatosaurus"; | |
sauropod(); | |
// TypeError: sauropod is not a function | |
if (sauropod === "apatosaurus") | |
console.log("We have the same favorite sauropod!"); | |
} |
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
// Implicit | |
console.log("20" + 18); // Logs: 2018 | |
console.log("20" * 18); // Logs: 360 | |
console.log(20 + true); // Logs: 21 | |
console.log("20" == 20); // Logs: true | |
console.log("20" === 20); // Logs: false | |
// Explicit | |
console.log(Number("20") + 18); // Logs: 38 | |
console.log(String(20) + String(true)); // Logs: "20true" |
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 favoritePlanets = ["Mars", "Saturn", "Earth"]; | |
console.log(favoritePlanets); // Logs: [ 'Mars', 'Saturn', 'Earth' ] | |
favoritePlanets.sort(); | |
console.log(favoritePlanets); // Logs: [ 'Earth', 'Mars', 'Saturn' ] | |
favoritePlanets.push("Jupiter"); // Logs: | |
console.log(favoritePlanets); // Logs: [ 'Earth', 'Mars', 'Saturn', 'Jupiter' ] | |
favoritePlanets[0].concat("2"); |
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 someGreeting = "hello"; | |
var otherGreeting = someGreeting; | |
console.log(someGreeting); // Logs: hello | |
console.log(otherGreeting); // Logs: hello | |
someGreeting.concat("!!!"); | |
// return value: "hello!!!" | |
console.log(someGreeting); // Logs: hello |
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
// Null testing | |
var myNullValue = null; | |
console.log(typeof myNullValue); // Logs: object | |
console.log(myNullValue === null); // Logs true | |
// Array testing | |
var myArray = []; | |
console.log(typeof myArray); // Logs: object | |
console.log(Array.isArray(myArray)); // Logs: true | |
console.log(Array.isArray({})); // Logs: false |