-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
66 lines (51 loc) · 1.35 KB
/
index.js
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
"use strict";
//1. Ways to print in JavaScript
//console.log("Hello World");
//alert("me");
//document.write("this is document write");
//2. JavaScript console API
//console.warn("this is a warning");
//console.error("this is an error");
//console.clear();
//console.assert(1 == 5);
//3. JavaScript Variables
// Containers to store data values
var number1 = 25;
var number2 = 45;
console.log(number1 + number2);
// 4. Data types in JavaScript
//string
var str1 = "This is a string";
var str2 = "This is also a string";
//objects
var marks = {
damon: 79,
elena: 88,
klaus: 63,
};
console.log(marks);
//Booleans
var a = true;
var b = false;
console.log(a, b);
// Contructor function and prototypes
const Person = function (firstName, birthYear) {
this.firstName = firstName;
this.birthYear = birthYear;
};
const person = new Person("Ahwar", 2000);
console.log(person);
console.log(person instanceof Person);
Person.prototype.calcAge = function () {
console.log(2021 - this.birthYear);
};
const matilda = new Person("Matilda", 2012);
const jack = new Person("Jack", 1991);
jack.calcAge();
matilda.calcAge();
console.log(jack.__proto__);
console.log(jack.__proto__ === Person.prototype);
console.log(Person.prototype.isPrototypeOf(jack));
console.log(Person.prototype.isPrototypeOf(Person));
Person.prototype.species = "Homo Sapiens";
console.log(jack, matilda);