• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Start selling Create your account
Document preview thumbnail
Preview 4 out of 84 pages
Lecture notes

Modern Javascript - Essentials

Document preview thumbnail
Preview 4 out of 84 pages

Online course notes on JavaScript

Content preview

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

Document information

Uploaded on
May 1, 2024
Number of pages
84
Written in
2020/2021
Type
Lecture notes
Professor(s)
Colt steele
Contains
All classes
£7.98

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
1
Last sold
-



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions