-
Notifications
You must be signed in to change notification settings - Fork 0
/
theory.txt
379 lines (261 loc) · 8.22 KB
/
theory.txt
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
Introduction
Hoisting
Types
Primitive Types
functions
Objects
arrays
Closures
Bind call apply
this
Prototypes
Class
Inheritance
Polymorphism
Error Handling
Singleton
Module Pattern
JavaScript (22/09/2020)
-----------
Javascript is a programming language that allows us to implement complex
features on web pages
HTML - is the markup language that we use to structure and give meaning to our
web content
CSS - is a language of style rules that we used to apply styling to our HTMl Cotent
Javsscript - is scripting language that enables you to create dynamically
updating content
Syntax Parser
-------------
A program that reads your code and determines what it does and if its grammar is valid
Lexical Environment
-------------------
Where something sits physically in the code we write
Execution Context
-----------------
A wrapper to help manage the code that is running
lexical 1 -
lexical 2
lexical 3
for e.g There are lots of lexical environments which one is currently
running is managed by execution context
Name/Value pairs
------------------
A name which mapes to a unique value (name: 'uma')
Object
-------
A collection of these name value pairs
Global environment and Global Object
------------------------------------
When ever code is running in javascript it runs inside an execution context
Execution Context (Global)
-------------------------
Global Object // javascript execution engine creating these two things for us
this
this - window ( this browser window)
Global Object - window
Global - means not inside the function
Hoisting
---------
When you declare variables and functions in javascript, the execution
engine sets up a memory space for variables and functions.
1. If it is a a variable it will keep that variable in memory and assign
a default value called undefined
2. If it is a function it will copy entire function and keeps in memory
1. find out all the variables and functions in the code file
a = undefined
function b() {
console.log('called b')
}
2. executing the code
This phenomenon is called hoisting
undefined (23/09/2020)
----------
Special value in javascript which takes up memory space
Warning : Never ever declare a variable undefined, because
it is difficult to find value is 'undefined' because
we set it or javascript execution engine set it up
Types
--------
Dynamic Typing
--------------
you don't tell the engine what type of data a variabe holds,
it figures out while your code running.
Strict Typing
-------------
C# or java follows script typing
Prmitive Types
-----------------
A type of data that represents a single value is called primitive data type
1. undefined - this represents lack of existance ( we should never use this)
2. null - this represents lack of existance ( we can set a variable to this)
3. Boolean - treu or false
4. number - integer/floating type(decimal)
5. string - a sequence oc characters
6. Symbol - used in ES6
Anythiing which is not primitive is an Object in javascript
object
function
array
Date
RegularExpression
Functions
--------------
Function is a block of code wrapped around flower brackets and invocated later
function functionname(){
}
1. Regular Functions
2. Anonymous Functions
3. Immediately Invoked functions ( IIFs)
First Class Functions
-------------------
1. can be Invoked
2. assign to a variable
3. passed as a parameter to another variable
Advantages with IIFs (24/09/2020)
--------------------
1. will not create unnecessary gloabal variables and functions
2. functions and variables defined don not conflict
Objects
--------
An Object is a collection of name value pairs
1. using New Object()
2. using Object Literal {}
3. using Object.create()
4. Construtor function
Object.create() method creates a new object using an existing
object or null as the protoype for newly created Object
var person = Object.create(null) // create an empty/null object
var person = Object.create({}) // create a normal function
JSON
-------
JavaScript Object Notation
common usage of
Inspired by the object literal notation {}
<data>
<firstname>uma</firstname>
<lastName>Mahesh</lastName>
</data>
JSON
------
common usage of JSON is to exchange data to/from web servers
When sending data to a webserver that data has to be string
{
"firstname": "uma",
"lastName": "Mahesh"
}
Object
---------
{
firstname: "uma",
lastName: "Mahesh"
}
poperties have to be wrapped in quotes for JSON
Anything which is JSON valid is valid in object literal
JSON.stringify - converts a javascript value into seriazlied string
JSOn.parser - deserialzes a JSON String to a JSON Object
arrays
-------
An array is an object that can store a collection of items
Useful when you want to store large amount of data
var students = ["Shanthanu", "Sunitha" , "Surekha", "Prdeep"]
var people = new Array("Uma", "Swathi", "Jagrav", "Manasvi)
In javascript arrays are object types with special constructor
var array = new Array(3) - length
var array = new Array(100000) - length will not create any memory
array index starts from zero
Closure (28/09/2020)
----------
Inner functions having access to the variables of outer functions
Bind vs call vs apply
-----------------------
bind - sets `this` keyword and creates a copy of that function
call - sets `this` keyword and execute the function immediately and
doesn't create a new copy of the function, it takes comma seperated values
apply - sets `this` keyword, similar to call but the difference is apply accepts
an array of arguments instead comma seperated values
The call, bind and apply methods can be used to set `this` keyword
independent of how function is called
Class (29/09/2020)
------------------
Javascript is a prototype-based language which contains no class statement
such as is found in C# or Java
Javascript uses function as a class
e.g.
function Student(){
}
instance
--------
To create instance of the class
function Person(){
}
var person1 = new Person();
var person2 = new Person();
constructor
-----------
function Order(){
console.log('Order is placed')
}
var order = new Order(); // Order() is called constructor
Properties
----------
function Customer(gender){
this.gender = gender
}
var customer1 = new Customer('Female')
var customer2 = new Customer('Male')
Prototype
----------
The prototype is an object that is associated with
every functions and objects by default in javascript
This is special type of obejct to which additional properties and methods can be attached.
Which will shared acorss all the instnaces of its contsructor function
Usages
------
1. extend properties and methods of an object
2. To implement inheritance
Object 'prototype'
-----------------
Every Object which is created using object literal syntax or constructor syntax
with new keyword includes __proto__ property that points to prortotype object of
a function that created this Object
Inheritance (1/10/2020)
-----------------------
One Object get access to the properties and methods of another object.
In Javascript inherirtance is supported by using prototype object.
This is also called prototypal inheritance.
Polymorphism
-------------
Means function existing in many forms.
In programming, the ability for objects to present the same interface
for different behaviour
Error Handling
---------------
Helps us to handle the errors (runtime), for accessing undefined variables
or undefined functions
try- catch-finally block
try {
// code that may or may not throws error
}
catch {
// code to be executed if an error occurs
}
finally {
// code to be executed regardless of an error occurs or not
}
Singleton Design Pattern
------------------------
Limits the number of instnaces of a perticular object to just one. This single instance
is called the Singleton.
Singletons are useful in stuations where system wide actions need to be coorodinated
from a single Central place
E.g Database Connection pool
The pool that manages the creation, destruction and lifetime of all database connections
for the entire application
Module Pattern
---------------
Deals with code encapsulation. It is used to create private publci properties
code encapsulation
-------------------
var person = function(){
var name = 'uma'
}