Rédigé par des étudiants ayant réussi Disponible immédiatement après paiement Lire en ligne ou en PDF Mauvais document ? Échangez-le gratuitement 4,6 TrustPilot
logo-home
Notes de cours

Modern Javascript - Essentials

Note
-
Vendu
-
Pages
84
Publié le
01-05-2024
Écrit en
2020/2021

Online course notes on JavaScript

Établissement
Cours

Aperçu du contenu

JAVASCRIPT ESSENTIALS

Dynamic typing: variables in JS are not directly associated with any particular value types
and any variable can be assigned (re-assigned) values of all types:



PRIMITIVE DATA TYPES
1 - undefined
2 - null - primitive value (typeof object)
3 - booleans
4 - symbols
5 - numbers
6 - strings

To check the type of data type = typeof

Ex: typeof 87 → number
typeof “87” → string



1. UNDEFINED
A variable that has not been assigned a value has the value of undefined.


2. NULL
The null type has one value: null. null value represents a reference that points, generally
intentionally, to a nonexistent or invalid object or address.

● Intentional absence to any value
let loggedInUser = null

● Must be assigned



3. BOOLEANS
Boolean represents a logical entity and can have two values: true and false. The words true
and false are special keywords in JS, and don't need quotes.



4. SYMBOLS
A Symbol is a unique and immutable primitive value and may be used as the key of an
Object property.

, Modern Javascript Bootcamp 2020



5. NUMBERS
A Number. Numbers don't have quotes around them.

To note:
● Unary notation = it increments or subtracts the value by 1.

○ ex: let myNum = 5;
myNum++;
myNum = 6

● NaN = Not a Number is considered a number data type.




MATH OBJECT
Contains properties and methods for mathematical constants and functions.

● To access the Math Object, we need to type in Math - with uppercase M
○ Math.floor(3.6951) //3 - decimal point gets chopped
○ Math.round(4.6) //5
Math.round(4.4) //4
● Math.pow(7,2) //49 - raise the first arg to the power
of the sec arg
● Math.random() - generate a random decimal between 0
and 1 but 1 is not included. If we need 10, we need to transform the number
in different ways:
○ Generate a random integer:
const step1 = Math.random(); //0.5464861654;
const step2 = step1 * 10; //5.464861654;
const step3 = Math.floor(step2) //5
const step4 = step3 + 1; //6

Math.floor(Math.random() * 10) + 1;


parseInt() & parse Float()
Use to parse strings into numbers:

● parseInt(“24”); //24 returns an integer
parseFloat(“24.544”) //24.544 returns a float number



6. STRINGS
A sequence of text known as a string. Must be enclosed it in quote marks.



2

, Modern Javascript Bootcamp 2020


Strings in JS are immutable, meaning that the individual value is not changeable.


● CONCATENATION
let firstName = “Ilaria”;
let surname = “Callegari”

fullName = firstName + surname;
Fullname = “Ilaria Callegari”

● STRINGS ARE INDEXED
Chicken
0123456

● STRINGS HAVE A LENGTH
.length → called dot syntax → used to access a property
“chicken”.length = 7;

● TO ACCESS A CHARACTER OF THE STRING
ex: let animal = “chicken”
animal[0] = “c”



STRING METHODS

Without arguments
Methods are built-in pieces of functionality - an action that can be performed in a particular
value.
ex: syntax - thing.methodName()

● let msg = “you are so grounded mr”

msg.toUpperCase()
// “YOU ARE SO GROUNDED MR”

● let msg = “YOU ARE SO GROUNDED MR”

msg.toLowerCase()
// “you are so grounded mr”

● let greeting = “ leave me alone plz ”

greeting.trim()
//”leave me alone plz”

greeting.trim().toUpperCase()


3

, Modern Javascript Bootcamp 2020


//”LEAVE ME ALONE PLEASE”

NB: .trim() will not remove the space between words.

With arguments



● .indexOf
let tvShow = “catdog”;

tvShow.indexOf(“cat”); // 0 - it starts at index 0
tvShow.indexOf(“dog”); // 3 - it starts at index 3
tvShow.indexOf(“z”); // -1 - not found

“baseball”.indexOf(“ball”); //4
“baseball”.indexOf(“b); //0 - tells you only the first instance
“Baseball”.indexOf(“b); //4 - case sensitive


● .slice()
Takes slices of an existing string and gives you a piece of it.

Ex: 1 argument - the index of the start of the slice
“Baseball”.slice(4); //”ball”

let sport = “Baseball”;
sport.slice(4); //”ball”
sport // “Baseball” - immutable

Ex: 2 arguments - the index of the start of the slice and of the end of the slice
“superhero”.slice(0,5); //”super” - non-inclusive (it ends at index 4)


● .replace()
It replaces part of a string

Ex:
“baseball is entertaining”.replace(“entertaining”, “ok”); //“baseball is ok”
“ha ha ha”.replace(“hee”); //”hee ha ha” - it only replaces the first one



STRING TEMPLATE LITERALS
Template literals are strings that allow embedded expressions, which will be evaluated and
then turned into a resulting string → interpolating data inside of a string.

Ex: `I counted ${3 + 4} sheep`; //“I counted 7 sheep”



4

École, étude et sujet

Établissement
Cours
Cours

Infos sur le Document

Publié le
1 mai 2024
Nombre de pages
84
Écrit en
2020/2021
Type
Notes de cours
Professeur(s)
Colt steele
Contient
Toutes les classes

Sujets

$10.85
Accéder à l'intégralité du document:

Mauvais document ? Échangez-le gratuitement Dans les 14 jours suivant votre achat et avant le téléchargement, vous pouvez choisir un autre document. Vous pouvez simplement dépenser le montant à nouveau.
Rédigé par des étudiants ayant réussi
Disponible immédiatement après paiement
Lire en ligne ou en PDF

Faites connaissance avec le vendeur
Seller avatar
ilariacallegari

Faites connaissance avec le vendeur

Seller avatar
ilariacallegari -
S'abonner Vous devez être connecté afin de suivre les étudiants ou les cours
Vendu
-
Membre depuis
1 année
Nombre de followers
0
Documents
1
Dernière vente
-

0.0

0 revues

5
0
4
0
3
0
2
0
1
0

Documents populaires

Récemment consulté par vous

Pourquoi les étudiants choisissent Stuvia

Créé par d'autres étudiants, vérifié par les avis

Une qualité sur laquelle compter : rédigé par des étudiants qui ont réussi et évalué par d'autres qui ont utilisé ce document.

Le document ne convient pas ? Choisis un autre document

Aucun souci ! Tu peux sélectionner directement un autre document qui correspond mieux à ce que tu cherches.

Paye comme tu veux, apprends aussitôt

Aucun abonnement, aucun engagement. Paye selon tes habitudes par carte de crédit et télécharge ton document PDF instantanément.

Student with book image

“Acheté, téléchargé et réussi. C'est aussi simple que ça.”

Alisha Student

Foire aux questions