File tree Expand file tree Collapse file tree 3 files changed +87
-0
lines changed
Lectures/Lecture01/24 Jan 2025 Expand file tree Collapse file tree 3 files changed +87
-0
lines changed Original file line number Diff line number Diff line change 1+ const info = {
2+ Name : "joy" ,
3+ Age : 21 ,
4+ City : "New York"
5+ }
6+
7+ console . log ( info ) ;
8+
9+ // accessing values
10+ console . log ( info . Name ) ;
11+
12+ // access form key
13+ console . log ( info [ "Age" ] ) ;
14+
15+ // adding new data
16+
17+ info . Country = "USA" ;
18+ console . log ( info ) ;
19+
20+ // add new function
21+ info . greet = function ( ) {
22+ console . log ( "welcome to codeswithpankaj" ) ;
23+ }
24+
25+ console . log ( info ) ;
26+
27+
28+ info . greet ( ) ;
Original file line number Diff line number Diff line change 1+ // create a global variable
2+
3+ var number = 10 ;
4+
5+ function printNumber ( ) {
6+
7+ // local var
8+ var data = 20 ;
9+
10+ // access the global variable
11+ console . log ( "The number is: " + number ) ;
12+ console . log ( "The data is: " + data ) ;
13+
14+ }
15+
16+ console . log ( "Accessing global variable outside function: " + number ) ;
17+ // console.log("Accessing local variable outside function: " + data);
18+
19+ function info ( ) {
20+ //console.log("call data inside info(): " + data);
21+ console . log ( "call number inside info(): " + number ) ;
22+ }
23+
24+
25+ printNumber ( ) ;
26+
27+ info ( ) ;
Original file line number Diff line number Diff line change 1+ class animal {
2+
3+ color = "white" ;
4+
5+ info ( ) {
6+ console . log ( "This is an animal class" ) ;
7+ }
8+
9+ type_dog ( name ) {
10+ console . log ( "Dog name is: " + name ) ;
11+ console . log ( "Dog type is: dengerous dog" ) ;
12+ console . log ( "Dog color is: " + this . color ) ;
13+ }
14+
15+
16+ }
17+
18+
19+ // create object
20+ const dog = new animal ( ) ;
21+
22+ // access method
23+ dog . info ( ) ;
24+
25+ // send data to method
26+ dog . type_dog ( "Labrador" ) ;
27+
28+ // send value to variable
29+
30+ dog . color = "black" ;
31+
32+ dog . type_dog ( "Bulldog" ) ;
You can’t perform that action at this time.
0 commit comments