One Pager Cheat Sheet
- Making JavaScript your friend is essential for any aspiring web developers, and the guide provided will help you assess your advanced knowledge in order to land the senior developer position.
- The output of this code will be Undefined Undefined Susan because of variable hoisting which causes
function declarations
andvariable declarations
to be moved to the top of the current scope, soname
is declared but not initialized when the code first executes. - Javascript
hoisting
can make variables and functions appeardeclared
before they are actually initialized, leading to confusion for beginners. - A
closure
is a function that has access to the variables in its parent's scope, even after the parent has returned. - A
closure
is used to keep a reference to the outer scope ofouterFunc()
, preserving the value ofa
(10) and allowingfunc()
to log the result ofa+b
(30). - A
closure
allows an inner function to access variables in its outer function, even after the outer function has returned and its local variable have gone out of scope. - A Javascript Promise is an object serving as a
proxy
that allows asynchronous operations to be handled in a synchronous manner, while representing the eventual result of the operation. Javascript promise
is an object that acts as a proxy for asynchronous functions and can exist in Pending, Fulfilled, or Rejected states.- Destructuring in JavaScript allows for easy extraction of values from an
object
or anarray
and assignment of those values tovariables
. - Using destructuring syntax with the
rest
keyword allows you toextract
an array's elements or object's properties into distinct variables in a real-world application. The
map
,filter
, andreduce
functions` enable developers to conveniently and quickly transform an array in a compact manner, without requiring explicit loops.- The
map()
method calls a callback function to add 10 to each element of the arrayarr
, resulting in a new array,mapped_arr
, with values of [11 12 13 14 15 16 17 18 19 20]. - The
map()
function in Javascriptloops
over an array and calls a callback on each element, returning a new array. - The
filter()
method of the Array object returns a new array containing the elements for which the providedcallback
expression returns atruthy
result. - Updated array is created with elements which satisfy the condition provided by
callback
function. - The
reduce
function applies a callback function (in this case,prev+next
) to each item in the array, starting from an initial value (1
), and returns a single value (55) which is the sum of every item in the array. - The
reducer
function uses a user-definedcallback
orreducer
function to apply areturn value
from a previous operation to thecurrent value
of anarray
. - An Immediately Invoked Function Expression (IIFE) is a
self-executing
anonymous function wrapped in parentheses()
. - An IIFE is used to
execute
an anonymous function immediately in order to keep variables and function declarations out of the global scope and avoid accidental interactions with other functions and variables. - A Immediately Invoked Function Expression (IIFE) is a self-executing anonymous function that is declared and called
instantly
with a grouping operator and()
to indicate its invocation.