Skip to content
Permalink
55682499e7
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
47 lines (41 sloc) 1.28 KB
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Object-oriented JavaScript example</title>
</head>
<body>
<p>This example requires you to enter commands in your browser's JavaScript console (see <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/What_are_browser_developer_tools">What are browser developer tools</a> for more information).</p>
<script>
const person = {
name: {
first: "Bob",
last: "Smith",
},
age: 32,
bio() {
console.log(`${this.name.first} ${this.name.last} is ${this.age} years old.`);
},
introduceSelf() {
console.log(`Hi! I'm ${this.name.first}.`);
},
};
const person1 = {
name: "Chris",
introduceSelf() {
console.log(`Hi! I'm ${this.name}.`);
},
};
const person2 = {
name: "Deepti",
introduceSelf() {
console.log(`Hi! I'm ${this.name}.`);
},
};
const myDataName = "height";
const myDataValue = "1.75m";
person[myDataName] = myDataValue;
</script>
</body>
</html>