JavaScript - JSON Tutorial Points (3)
Use curly brackets to create JSON like JavaScript object and add properties and functions to the object.
JSON is a type of data-saving format.it saves data using key and value pairs.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="XX-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AF LAB 01 - Ex 02</title>
<!-- JSON is a type of data saving format.it saves data using key and value pairs -->
</head>
<body>
<script>
/*Use curly brackets to create JSON like JavaScript object and add properties and
functions to the object */
let student = {
first : "Kamal",
second : "Perera",
age : 44,
welcome: function(){
return `${this.first} is ${this.age} years old`;
}
};
document.write("<h1>" + student.first+"</h1>");
document.write("<h1>" + student.age+"</h1>");
document.write("<h1>" + student.welcome()+"</h1>");
//Undefined variabel => id
document.write("<h1>" + student.id+"</h1>");
//This is wrong use () tomethod
document.write("<h1>" + student.welcome+"</h1>");
</script>
</body>
</html>
OutPut :
Comments
Post a Comment