• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 4 fuera de 84 páginas
Notas de lectura

Modern Javascript - Essentials

Document preview thumbnail
Vista previa 4 fuera de 84 páginas

Online course notes on JavaScript

Vista previa del contenido

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

Información del documento

Estudio
Subido en
1 de mayo de 2024
Número de páginas
84
Escrito en
2020/2021
Tipo
Notas de lectura
Profesor(es)
Colt steele
Contiene
Todas las clases
$10.70

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
1
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes