Repository navigation
Expand file tree
/
Copy pathprogram25.js
More file actions
68 lines (56 loc) · 1.56 KB
/
Copy pathprogram25.js
File metadata and controls
68 lines (56 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// object program example
// what is Object?
// How to create an object?
// How to access object properties?
// Constructor, this keyword
// function inside constructor
// declaring variables and using them
var name = "Anisul Islam";
var age = 27;
var cgpa = 3.92;
var lang = ["Bengali", "English"];
// declaring objects -> object is one type of variable that can store differnt types of variables
var student1 = {
// property : value
name: "Anisul Islam",
age: 27,
cgpa: 3.92,
lang: ["Bengali", "English"],
}
var student2 = {
// property : value
name: "Rokib",
age: 28,
cgpa: 2.92,
lang: ["Hindi", "Bengali"],
}
var student3 = {
// property : value
name: "Sweety",
age: 25,
cgpa: 4.92,
lang: ["Bengali", "Urdu"],
}
// printing object property's value
// object properties can be accessed in two ways: objectName.propertyName or objectName["propertyName"]
console.log(student1.name);
console.log(student1[name]);
console.log(student1);
console.log("using constructor");
// adding constructor and simplifying the task
function Student(name, age, cgpa, lang) {
this.name = name;
this.age = age;
this.cgpa = cgpa;
this.lang = lang;
// adding function inside the constructor
// this.display = function () {
// console.log(this.name);
// }
}
var s1 = new Student("Anisul Islam", 27, 3.92, ["Bengali", "English"]);
var s2 = new Student("Rabeya Begum", 23, 4.92, ["Bengali", "Urdu"]);
var s3 = new Student("Milon", 29, 4.68, ["Bengali", "Hindi"]);
console.log(s1);
console.log(s2);
console.log(s3);