Please enable JavaScript.
Coggle requires JavaScript to display documents.
W9 - JS Patterns [Part 1] (OOP Concepts (Objects Representation of a…
W9 - JS Patterns [Part 1]
OOP Concepts
Objects
Representation of a things expressed with
help of programming language
Class
Encapsulation
In
compiled
languages,
cannot read code
that makes object work, In JS becuase
interpreted language
can see code, work with
object's interface
without worrying its **implementation
Aggregation
Combining
several objects into a
new one
Separate
problem into
*smaller more manageable
Reusability/Inheritance
In JS,
objects inherit from other objects
since
no classes
overriding
Polymorphism
Ability to call
same method
on different objects and have each of then
respond in their own way
Variables
used to
store data
.
2 steps:
declare and initialize
Primitive data types
Number
String
Boolean
Undefined
Null
using
typeof
want to
know type
of variable or value.
Returns
string that
represents data type
typeof n;
Arrays
A
list of values
. Instead of using one variable to store one element, use one
array variable
to store
any number of values as elements
.
var a = [ ];
var a = [1,2,3];
Updating/Adding array
a[2] = 'three';
.
If array updated
with gap
in between, they
don't exist
and return
undefined
Deleting elements
delete a[1]
after deletion,
size of array does not change
. You get
hole
Conditions and Loops
Conditions
Provide way to
control flow of code execution
If Condition contains
if statement
condition in parentheses
block of code wrapped in { } if condition satisfied
Switch Condition
consider if condition having
too many else
Loops
Allows to
perform repetitive operations
with
less code
While loops
do-while loops
For loops
For-in loop
for (var i in a)
Functions
allows to
group together code
, give
code a name
and
reuse it, addressing it with name given
Anonymous Functions (function with no name)
can pass as
a parameter
to another function
define anonymous and execute right away
Callback Functions
Accept functions as parameters
function add(a, b){
return a( ) + b( );
}