Home | HTML | Data Types | DOM | JavaScript | JS Debugging |
Scenario
This object represents me and the information that goes with such. With this object, I perform a lot of different to show you the power of Data Types!
%%js
// Me Object
let me = {
name: "Xavier",
age: 14,
birthYear: 2009,
classes: ["ENS", "Math", "Spanish", "CSSE", "Science"],
interests: ["Cybersecurity", "Coding", "Sports", "Science"],
group: ["Justin", "Daniel", "Timur"],
schools: ["MRES", "OVMS", "DNHS"]
}
//Prints Object
console.log(me)
// Adds Psychology to Interests Array
me.interests.push("Psychology");
//Concanetating Classes
console.log(me.classes[1] + " and" + " " + me.classes[3] + " are my favorite classes!");
//Concanetating Schools
console.log("First I went to " + me.schools[0] + ". Then I went to " + me.schools[1] + ". And now I'm in " + me.schools[2])
// Usage of Mathematical Operations //
// Add age + birth year to get current year
let currentYear = me.age + me.birthYear
// Print current year
console.log(currentYear)
// Prints what type of value specified variable is
console.log(typeof me.name) // Prints String
console.log(typeof me.age) //Prints Number
console.log(typeof me.classes) //Prints Object
<IPython.core.display.Javascript object>