Skip to content

Instantly share code, notes, and snippets.

View sevperez's full-sized avatar

Severin Perez sevperez

View GitHub Profile
using System;
public class Program
{
public static void Main()
{
int myInt = 8;
double myDecimal = 8.5;
string myString = "electron";
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}"
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 {
function cloneDinosaur(name) {
try {
var myDinosaur = {
name: name,
dangerMessage: name.toUpperCase() + " IS COMING!!!",
};
return myDinosaur;
} catch (e) {
console.log(e.name + ": " + e.message);
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!
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!");
}
// 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"
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");
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
// 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