























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Learn Javascript basic programming and functional
Typology: Summaries
1 / 31
This page cannot be seen from the preview
Don't miss anything!
The
method
is used
to log
or
messages to
the console.
It
can
also be
used
to print
objects
and other
info.
JavaScript
is
a
programming language that
powers
the
dynamic behavior
on most websites.
Alongside
HTML
and
CSS, it
is
a core technology
run.
Methods
return information about
an
object, and
are
called by appending
an
instance
with
a
period.the
method
name,
and
parentheses.
Built-in objects contain methods that
can
be called by
appending the object
name with
a
period the
method
name,
and
a
set of parentheses.
Numbers
are
a
primitive data
type. They include the
of all integers and floating point numbers.
The
property of
a
string returns
of characters that
make
up
string.
0
1
1/Math is
built-in
=
=
=
nite':
9
5
When
a new piece of data
is introduced into
a
JavaScript
program,
the
program
keeps track of
it in
an
instance of
that data
type. An instance
is
an
individual
case
of
a
data
type.
Booleans
are
a
primitive data type. They
can
be either
or
The
method
returns
a
floating
point, random number
in the
range
from 0
(inclusive)
up
to but
not including
The
function
returns the largest
integer less than
or
equal
given number.
In JavaScript, single-line comments
are
created
with two
consecutive forward slashes
Null is
a
primitive data type.
It
the
intentional
absence of value.
In
code, it
is represented
as
Strings
are
a
primitive data
type. They
are any
grouping
of characters (etters,
spaces,
numbers,
or symbols)
surrounded
by single quotes
or
double
quotes
=
0
5
x
=
=
my
=
my
An assignment operator assigns
a
value
to its left
operand based
on
value of its right operand. Here
are some of them:
+=
addition assignment
subtraction assignment
*=
multiplication assignment
.
division assignment
String interpolation is the
process of evaluating string
literals containing
one or more placeholders
(expressions, variables, etc).
It can
be performed
using template
literals:
text
Variables
are
used whenever there's
a
need
to store
a
piece of data.
A
variable contains data that
can
be used
in the
program
elsewhere.
Using variables also
ensures
code
re-usability since
it
can
be used
to replace the
same value
in multiple places.
is
a
primitive JavaScript value that
represents lack of defined
are
declared but
not initialized
to
a
value
will have the value
=
=
+=
=
'Tommy is
is
const urrency
=
=
old. ':
1/
Prints:
is
;
A variable is
a
container
for data that
is stored
in
computer
memory. It is
a
descriptive
name
that
a programmer can
a
specific
value and retrieve
it.
To declare
a
variable
in JavaScript,
any
of
keywords
can
be used along with
a
variable
name:
used
in pre-ES6 versions of JavaScript.
is
the preferred
way
to declare
a
variable
when
it
can
be
reassigned.
is
the
preferred
way to
declare
a
variable with
a
constant value.
Template literals
are
strings that
allow
expressions,
regular
strings
quotes, template
literals
use use
single
or
double
backticks instead.
let
a
local variable
in JavaScript
& can
be
re
assigned. Initialization during
declaration of
a
variable
is optional.
A
variable
will contain
if nothing
is assigned to
it.
const
A constant variable
can
be declared using the
keyword
must have an assignment.
Any attempt of
assigning
a
variable
will result
in JavaScript
runtimne
error.
ame = "Tammy";:
=
=
Tammy
false
3
let
=
let
name
=
Hello, ${name}
);1/
is
/I
COunt
=
10
=
=
to
Control
flow is the order
in which
statements
are
executed
in
a program.
The default control
flow is for
statements
to
be read
and executed
in
order
from left
to-right, top-to-bottom
in
a program file.
Control structures such
as
conditionals
(
statements
and
like)
alter
control flow by only executing blocks
of code
if
certain conditions
are met. These
structures
essentially
allow
a program
decisions about
which code
is
executed
as
the
program runs.
|
The logical OR operator ||
checks
two values and
returns
a
boolean.
If one or both values
are truthy, it
returns
both values
are falsy, it returns
A
B
A
B
The
for
a
compact
syntax in the
case
of binary (choosing between
two choices) decisions.
It accepts
a
condition followed
by
a
operator, and
then
two expressions separated by
a
condition
evaluates
the
first expression
is
exe
cuted,
otherwise, the second
expression
is
executed.
10
5
10
false
10
=
let
=
1/ false
day
===
:
+=
An
block
can
be added
to
an
block
or
series
of
blocks. The
block
will
be
executed
only
if
the
condition
fails.
&&
The logical
AND operator
&&
checks
two values and
returns
a
boolean.
If
both values
are truthy, then
it
returns
one, or
both,
of the
values is falsy,
then
it
returns
The
statements provide
a means
of checking
an
If
a case
matches, the code
inside that
clause is executed.
The
clause should
finish with
a
keyword.
If no case
matches but
a
clause
is
included, the code inside
will be executed.
Note:
If
is omitted from the
block of
a
statement will continue
to check against
values
until
a
break
is encountered
or
the
flow is
broken.
An
statement accepts
an
expression
with
a set of
parentheses:
If
the
expression evaluates
to
a
truthy value, then
the code
within its code
body executes.
If
the
expression evaluates
to
a falsy value,
its
code
body
will not execute.
=
if
{
}
{
}
&&
1
2
&& 2
&&
===
&& 3
{
=
}
taste of
||
||
{
=
In
JavaScript,
values evaluate
to
or
when evaluated
as
Booleans.
Values that evaluate
to
are known
as
truthy
Values that evaluate
to
are
known
as
falsy
Falsy values include
empty strings,
and NaN.
All other values
are truthy.
Arrow function
expressions
were
introduced
in ES6.
These
expressions
are
clean and concise. The
syntax for
an arrow
function
expression does
not require the
keyword and
uses
a
fat
arrow
to
separate the
parameter(s) from the
body.
There
are several variations of
arrow
functions:
Arrow functions
with
a
single parameter do
not
require () around the
parameter list.
Arrow functions
with
a
single expression
can use
the
concise function body which
returns
the
result
of the
expression without the
keyword.
sum
=
=>
{
}:
7
=
=> {
}:
'hello'
)
;
1/
=
=> {
:
}:
I/
Prints:
:
=
return
Functions return (pass back) values using
keyword.
ends function execution and
returns
specified value the
location where it
was
called.
A
common
mistake
is to forget the
keyword,
in which
case
the
function
will return
by default.
Function declarations
are
used
to create named
functions. These functions
can
be called using their
declared
name.
Function declarations
are built from:
The
keyword.
.
The function
name.
commas
enclosed
by
a
set
of
parentheses )
A function body enclosed
in
a
Functions
can
be called,
or executed, elsewhere
in code
using parentheses following
name.
When
a
function
is called, the code inside its function body
runs.
Arguments
are
values passed into
a
function when
it is
called.
num2 )
{
num
+t
sum
{
num
{
num
1/
{
num
//
6
Scope
Scope
is
a concept that refers
to where values and
functions
can
be accessed.
Various
scopes
include:
Global
scope la value/function
in the
global
scope can
be used anywhere
in
entire
program)
File
or
module
scope
(the value/function
can
only be accessed from
within the
file)
Function
scope
(only visible within the
function),
Code block
scope (only visible withina
{
}
codeblock)
and
are block scoped variables, meaning
they
are
only accessible
in
their
block
or
nested blocks.
In
given code
block, trying
to print the
using
method
will
result
in
a
is
accessible
only inside that
block.
JavaScript variables that
are
declared
outside of blocks
or
functions
can exist in the
global
scope, which
means
they
are
accessible throughout
a program. Variables
declared outside of smaller
block
or
function
scopes are
accessible inside those smaller
scopes.
Note:
It is best practice
to keep
global variables
to
a
minimum.
{
=
1/
isLoggedIn
=
if
==
true)
{
=
=
}
{
//
JavaScript
arrays are
mutable, meaning that the values
they contain
can
be changed.
Even if they
are
contents
can
be manipulated
by reassigning
values
or
using methods
like
and
Arrays
are
lists of ordered, stored data.
They
can
hold
items that
are of
any
data type. Arrays
are
created
by
using
square
brackets,
with individual elements
separated
by
commas.
=
1/'Alice'
1/
=
//
different
=
Loops
A
loop
can
iterate "in reverse"
by initializing
the
loop variable to the
starting value, testing for when the
variable hits the ending value, and decrementing
(subtracting from)
loop variable at each iteration.
A
statement
a
loop
exe cutes
a
block of code
once,
checks
if
a
condition
is
the loop
as
long
as
condition
are
used when
you
want
code
to always
execute at least
once.
evaluates
to false.
=
i
=
=
i
{
1/ Prints: 2. cherry
Prints: 0. apricot
X
=
0
=
0
{
X
= X +
}
<
1/ Prints:
0 1
3 6 10
A nested
loop
is when
a
loop
runs
inside
loop.
The inner loop
will
run all its iterations for
iteration
of the
A loop is
a
programming tool that
is
used
to repeat
a
set
of instructions. Iterate
is
a
generic term that
means "to
repeat"
in the
context of loops.
A
loop
will
continue
to
iterate
until
a
specified condition, commonly known
as a
stopping
condition,
is met.
The
loop
creates
a
loop that
is executed
as
long
as a specified condition evaluates
to
The loop
will continue
to
run
until the
condition evaluates
to
The condition
is specified before the loop, and
usually,
some
variable
is incremented
or
altered
in the
loop body
to determine
when
should
stop.
=
<
{
=
<
+=
{
=
<
{
In JavaScript, functions
are
a
data
type just
as
strings,
numbers, and
arrays are
data
types. Therefore,
functions
can
be
assigned
as
values
to variables, but
are
different
from
all
other
data types because
they
can
be
invoked.
In JavaScript,
a
callback function
is
a
function that
is
passed into another function
as an argument. This
function
can
then be invoked during the execution
of
higher
it is
an argument of).
Since,
in JavaScript, functions
are
objects, functions
can
be passed
as
arguments.
let
=
=> {
=
8
14
=
=> {
n % 2
==
0;
=
=> {
=