Let's Talk about
Javascript
Johan Esteban Higuita
Software Developer at Talent.com
Bioengineer - Universidad de Antioquia
Session 4
Let's Talk about Javascript
Let's Talk about Javascript
Let's Talk about Javascript
Let's Talk about Javascript
Arrays
Sets
Maps
Store data of any kind and length
Iterable, also many special array method available
Order is guaranteed
Duplicates are allowed
zero-based index to access element
Store data of any kind and length
iterable, also some special set methods available
Order is NOT guaranteed (!)
Duplicates are not allowed
No index-based access
Store key-value data of any kind and length, any key values are allowed
Order is guaranted
iterable, also some special map methods available
Duplicates are not allowed
key-based access
Let's Talk about Javascript
Let's Talk about Javascript
Store unique values of any type
const ids = new Set();
constructor:
Main methods:
Some Performance considerations:
new Set( [iterable] )
Code...
Let's Talk about Javascript
Let's Talk about Javascript
Collection of elements where each element is stored as a Key, value pair
constructor:
new Map( [iterable] )
Main methods:
Some Performance considerations:
Code...
Let's Talk about Javascript
Let's Talk about Javascript
Maps
Objects
Can use any values (and types) as keys
Better performance for large quantities of data
Better performance when adding/removing data frequently
Only may use strings, numbers or symbols as keys
Perfect for small/medium-sized sets of data
Easier / quicker to create
data is stored in consecutive memory
The number of items is easily retrieved from its size property
The number of items must be determined manually
WeakSet & WeakMap
Let's Talk about Javascript
Let's Talk about Javascript
A different way of defining functions
Function statement
Function Expression
function add(a, b){
return a + b;
}
const add = function(a, b){
return a + b;
}
Hoisted to top, can be declaraded anywhere un the file
Hoisted to top but not initialized.
Can't be declaraded anywhere in the file
Code...
Let's Talk about Javascript
Let's Talk about Javascript
Immediately Invoked Function Expression:
runs as soon as it is defined.
Let's Talk about Javascript
Let's Talk about Javascript
(arg1, arg2) => { ... }
General Syntax:
No arguments
Empty pair of parentheses is requires
Exactly one argument
Exactly one expression in function body
More than one expression in function body
Parentheses can be omitted
Curly braces can be omitted, result is returned
Curly braces and return statement required
() => { ... }
arg => { ... }
(a, b) => a + b
(a, b) => {
a *= 10;
return a + b;
}
Code...
Let's Talk about Javascript
Inside funtions, 'this' will refer to the "thing" which called that function:
Using arrow functions!!!
Code...
Let's Talk about Javascript
this keyword
arrow function
Arrow functions do not know this shit keyword!!!
In arrow functions, this refers to the global object
Let's Talk about Javascript
non-arrow function | arrow function | |
---|---|---|
Called in the global context | Global Object | Global Object |
Called on an Object | The Object | Global Object |
Let's Talk about Javascript
Let's Talk about Javascript
Thank you!