(SIC) Complete Path To JavaScript Mastery
(SIC) Complete Path To JavaScript Mastery
00 Introduction
04 Functions
05 Tricky Concepts
06 Strings in Detail
07 Arrays in Detail
08 Objects in Detail
Chapters
09 Value vs Reference
12 Asynchronous JavaScript
14 Additional Resources
Chapter 00
Introduction
Intro to JavaScript
Welcome! In this introductory section, you'll learn
everything there is to know about the most
popular programming language in recent
history! Before we start let's quickly learn what
exactly JavaScript is and why you need to learn it
if you want to be a professional developer.
Variables
The variableName is the name of the variable
which you can freely choose.
Multi-line comments
Single-line comments
Comments
Multi-line comments
To write a comment that stretches over more
than one line, you can use a multi-line comment,
starting with the
int wholeNumber = 5;
const wholeNumber = 5;
+ Addition
- Subtraction
* Multiplication
/ Division
Numbers
When we try to do some operations with values
that are not numbers, most often, we will get NaN
as a result. NaN simply means, not a number, it
represents a computational error.
console.log(tyepof NaN);
Numbers
The type of NaN, which stands for Not a Number
is, surprisingly, a number.
NULL
UNDEFINED
is undefined.
let x;
console.log(tyepof NaN);
Null and Undefined
any variable:
let x = 123;
x = undefined;
alert(x); // "undefined"
value to a variable.
UNDEFINED VS NULL
null is an object.
programmatically.
Objects
Object is the most important data-type and
forms the building block for modern JavaScript.
const person = {
name: 'John',
age: 25;
person.name
person.age
...And so on.
Objects
They have their special features that we’ll study
later. Sometimes people say something like
“Array type” or “Date type”, but formally they are
not types of their own, but belong to a single
“object” data type.
That's all that I'm going to let you know for now.
Objects are complex concepts. First, let's master
the easy things, and then we can get back to
them later.
Statically vs Dynamically
Typed Languages
There are two types of languages when it comes
to data types:
message = 123456;
1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators
4. Assignment Operators
5. Conditional Operators
+ Addition
- Subtraction
* Multiplication
/ Division
() Grouping operator
% Modulus (remainder)
++ Increment numbers
-- Decrement numbers
Arithmetic Operators
true == 1;
// true, because the string of "5" is converted
to the number 5 and then compared
5 == “5”;
Using the === operator
5 == “5”; // true
Loose equality
This isn't and should never be equal. "5" is a string,
and should be treated like that. As I mentioned,
most of the JavaScript developers completely
avoid loose equality and rely only on the strict
equality. It is considered a better practice and it
causes less bugs.
logical operators:
&& AND
|| OR
! NOT
console.log(!true); // false
console.log(!false); // true
const number = 5;
going to be skipped.
laws.
your console?
we expected. Awesome!
Logic and Control Flow
FALSY Values
false
0 (zero)
null
undefined
&& AND
|| OR
! NOT
And Operator (&&)
Double ampersand && is known as AND operator.
It checks whether two operands are truthy
values. And if they are truthy, it returns true,
otherwise it returns false. They are often used as
a condition in an if statement.
console.log(!true); // false
alert(!true); // false
alert(!10); // true
alert(!!'truthy'); // true
alert(!!null); // false
Ternary Operator
Although this is just a pseudocode, meaning the
code written in half english and half real syntax, I
think you can still see how we would use the
ternary operator.
on the console.
block statement).
Functions
Functions Intro
times by now.
Function:
Defining functions
creating a function.
known as parameters.
JavaScript.
Calling Functions
square(5);
Functions Intro
known as arguments.
25
Tricky Concepts
Tricky Concepts intro
In the upcoming 3 sections we're going to cover
some tricky concepts in JavaScript. Scope,
Hoisting and Closures.
1. Global Scope
2. Local Scope
3. Block Scope (only with let and const)
KEY DIFFERENCE
Local variable is declared inside a function
whereas Global variable is declared outside the
function.
console.log(name);
console.log(myString); // undefined
var myString = 'test';
var myString;
console.log(myString); // undefined
myString = 'test';
Variable Hoisting
Example 1:
var hoist;
console.log(hoist); // undefined
hoist = 'The variable has been hoisted';
Example 2:
Variable Hoisting
Only declarations are hoisted
JavaScript only hoists declarations, not
initializations. If a variable is declared & initialized
after using it, the value will be undefined.
For example:
console.log(num); // undefined
var num;
num = 6;
Function expressions
Another great thing, is that constants & function
expressions save us from doing that. Function
expressions (the more modern way of writing
functions, with const keyword), are not hoisted.
Function Hoisting
Strings in Detail
Strings Intro
value.
Strings Intro
'2 + 2'.
Strings Intro
of the code.
want. Great!
String Escape Characters
\' Single quote
\" Double quote
\\ Backslash
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Horizontal tabulator
\v Vertical Tabulator
String length and basic
properties
One thing that we often want to know when it
comes to strings is its lenght.
name.[0] // j
name.[name.length - 1] // n
name.[2] // h
string.toLowerCase()
string.toUpperCase()
str.indexOf()
The first method is str.indexOf(substr, pos).
can be found.
For instance:
Searching for a Substring
The optional second parameter allows us to
search starting from the given position.
str.lastIndexOf()
str.lastIndexOf(substr, position)
includes()
But much more often, you're just interested if a
string contains something, and you're not
concerned where is it in the string.
str.slice(start [, end])
Returns the part of the string from start to (but
not including) end.For instance:
Searching for a Substring
Some times, we might want to split the string into
multiple substrings. For that we'll be using a string
method called split().
So this is a process.
1. Split a string
2. Reverse newly created a array
3. Turn the array back into string using join()
Repeat and trim a string
REPEAT
Let's say that you want to repeat a string an x
number of times. You can easily do that by using
the string.repeat() method.
TRIM
Sometimes, users don't know how to type. And we
need to clean their emails, usernames & whatnot.
We can clean empty spaces using trim
Array Methods
string[index]
get a certain character of a string
string.length
return the number of characters in a string
string.split(' ')
returns an array of words of a string
string.split('')
returns an array of characters of a string
string.toLowerCase()
returns a lowercased string
string.toUpperCase()
returns an uppercased string
Array Methods
string.charAt(index)
returns a new string consisting of the single
character located at the specified offset into the
string.
string.replace(substr, newSubstr)
returns a new string with a substring (substr)
replaced by a new one (newSubstr).
string.includes(searchString)
performs a case-sensitive search to determine
whether one string may be found within another
string, returns true or false.
string.substr(start, length)
returns a portion of the string, starting at the
specified index and extending for a given number.
Array Methods
string.includes('subtring')
checks whether a substring exists inside of a string
string.indexOf(searchValue)
returns the index of the first occurrence of the
specified value, starting the search at fromIndex.
Returns -1 if the value is not found.
string.lastIndexOf(searchValue)
returns the index of the last occurrence of the
specified value, searching backwards from
fromIndex. Returns -1 if the value is not found.
string.slice(beginIndex, endIndex)
extracts a section of a string and returns it as a new
string, without modifying the original string.
Chapter 07
Arrays in Detail
Arrays
In programming, quite often we will need an
ordered collection, where we have a 1st, 2nd, 3rd
element and so on.
Declaration
This is how we declare an array - the most
important part here are the square brackets:
array.push(value)
The array.push() function adds a new element,
containing the entered variable, to the end of the
array.
Array Methods
There's one important thing that many
experienced web developers don't know about
array.push(). What's it's the return value?
array.pop()
The array.pop() function on the other hand,
does quite the opposite, deleting the last element
of an array.
array.shift()
Shift works almost exactly like pop, with one
major difference. It deletes the first value in an
array and moves the rest backwards!
Array Methods
It too returns the "popped" value.
array.unshift(value)
If shift is the sister function to pop, unshift is that
to push. It adds a new value to the start of an
array instead of the end!
array.splice()
Now this one is a little more sophisticated, but
don't worry we'll walk you through it.
push(value)
adds the value to the end of the array
pop()
removes the value from the end of the array
shift()
removes the value from the start of the array
unshift(value)
adds the value to the start of the array
splice(fromIndex, no_of_elements)
removes the number_of_elements, starting from
fromIndex from the array
Array Methods
slice(fromIndex, toIndex)
copies a certain part of the array
concat()
Join several arrays into one
join('')
returns a string of array values
array.length
returns the number of elements in the array
reverse()
reverse the order of the elements in an array
toString()
returns a string representing the specified array
includes(searchElement)
determines whether an array includes a certain
value among its entries, returning true or false as
appropriate.
sort()
It sorts the elements of an array in place and returns
the sorted array. It sorts an array alphabetically.
indexOf(searchElement)
returns the index of the first occurance of that value
lastIndexOf(searchElement)
returns the index of the last occurance of that value
Array Methods
array.slice()
And finally, the slice function. This handy little
piece of code can make a new variable that
contains every element from a certain point on
})
array.map()
It creates a new array populated with the results of
calling a provided function on every element in the
calling array.
})
Array method for looping
array.filter()
It creates a new array with all elements that pass the
test implemented by the provided function.
})
array.findIndex()
It returns the index of the first element in the array that
satisfies the provided testing function
})
Array method for looping
array.some()
It tests whether at least one element in the array
passes the test implemented by the provided function
})
array.every()
It tests whether all elements in the array pass the test
implemented by the provided function. It returns a
Boolean value.
})
Array method for looping
array.reduce()
It runs a function on each array element to produce
(reduce it to) a single value. It works from left-to-right.
array.reduce((prevValue,currentValue,
})
array.reduceRight()
It runs a function on each array element to produce
(reduce it to) a single value. It works from right-to-left.
array.reduceRight((accumulator,
})
Chapter 08
Objects in Detail
Intro to Objects
Objects are the most important data type and
building block for modern JavaScript.
person.firstName;
person['firstName'];
object.methodname(params);
this.displayCar = displayCar;
car1.displayCar;
car1.displayCar;
Chapter 09
Primitive values
(Number, String, Boolean, Null, Undefined...)
Complex values
(Objects, Arrays)
Copying Strings
Copying Arrays
Copying Objects
Equality
We can prove that with a simply equality check.
Cloning Arrays:
numbers array.
console.log(...numbers); // 1, 2, 3, 4, 5
Shallow Cloning
console.log(newNumbers); // [1, 2, 3, 4, 5]
Shallow Cloning
numbers array:
Cloning Objects
operator as well.
Shallow Cloning
changing person:
SHALLOW CLONES.
Deep Cloning
console.log(person); // unchanged
console.log(newPerson); // changed
console.log(person); // changed
console.log(newPerson); // changed
newPerson.car.color = 'red';
console.log(person); // unchanged
console.log(newPerson); // changed
That's great! But this only works for two levels into
depth, first level is when we're inside of the
person object, and second level is when we're
inside of the car object.
Deep Cloning
But if we had more nested objects, we'd need to
spread everything. And that's not the solution.
When we have deeply nested objects, we need to
create a deep clone. For an object to be a deep
clone, it needs to destroy all the references.
DOM -
and Methods
Html elements can have different attributes
assigned to them like id, class, type etc.
and Methods
if you assign type to a div and try to access it it is
will be undefined.
Properties
classlist
a list of class assigned to an element - not a string its
a array
id
string of the id assigned to an element
Element Properties
and Methods
classname
string of classes assigned to an element - if there are
more than one class separated by space
innerHtml
inner content of the element - if has nested elements
then in string form
Properties
addEventListener
listen to a any type of event and call some function
when that event has occurred. types can be click,
mousedown, mouseup, focus, blur etc.
hasAttribute
method to check if an element has an attribute or not
Element Properties
and Methods
removeAttribute
remove some attribute assigned to an element
getBoundingClientRect
returns the height, width, left and top values of an
element related to the browser
removeEventListener
remove event listener from an element
scroll
scroll to an element position
Element Properties
and Methods
Usage of above properties is shown below
Working with classes
Mostly developers think classes are used mostly
to style the elements.
Syntax
ele.childNodes ele.previousSibling
ele.firstChild ele.nextSibling
ele.lastChild
ele.parentNode
Creating, Traversing
newPerson.lastName = 'John';
console.log(person.lastname); // John
console.log(typeof(person)); // object
The "new" Keyword
So the most basic thing that new keyword
performs is create an empty object
Asynchronous JavaScript
Intervals and Timers
Welcome to a new module in this eBook! I am
super excited for this one, because now we're
going to understand some important concepts in
Javascript. These concepts will later help us
provide functionalities to our app like fetching
data and sending data to servers.
setInterval():
The setInterval allows you to execute a chunk of
code every time a specified amount of
milliseconds passes.
Intervals and Timers
For example; this code logs "Hello World" every
thousand milliseconds:
setTimeout():
The setTimeout function allows you to wait a
certain amount of time before executing a chunk
of code, do note that other code outside of the
timeout will continue execution as normal. The
way it's used is identical to setInterval.
Intervals and Timers
It is cleared using the function clearTimeout();
What is Async-Await?
promises.
async function.
Modern JavaScript
2. Arrow Functions
The second ES6 addition on the list are our
beloved arrow functions. We've used them a lot
throughout the course and by now you should be
really familiar with them.
ES6+ JavaScript
Arrow functions allowed us to change our code
from:
...to:
4. Template Strings
What if I told you that you can add a variable or
an object information directly as a string?
How do we do it?
Imports and Exports
This is often used in React.
Spread & Rest
Spread syntax allows an iterable such as an
array expression or string to be expanded in
places where zero or more arguments (for
function calls) or elements (for array literals) are
expected, or an object expression to be
expanded in places where zero or more key-
value pairs (for object literals) are expected.
Spread & Rest
The rest parameter syntax allows a function to
accept an indefinite number of arguments as an
array, providing a way to represent variadic
functions in JavaScript.
Array Destructuring
The destructuring assignment syntax is a
JavaScript expression that makes it possible to
unpack values from arrays, or properties from
objects, into distinct variables.
Additional Resources:
Resources
LeetCode
https://leetcode.com/
Coderbyte
https://coderbyte.com/
Resources
30secondsofcode
https://30secondsofcode.org/
Exercism
https://exercism.org/
Codewars
https://codewars.com/
Frontend Mentor
https://frontendmentor.io/
Resources
Loading.io
https://loading.io/
Lottie Files
https://lottiefiles.com/
Images
Unsplash
https://unsplash.com/
Pexels
https://pexels.com/
Pixabay
https://pixabay.com/
StockSnap
https://stocksnap.io/
Illustrations
Freepik
https://freepik.com/
Storyset
https://storyset.com/
Undraw
https://undraw.co/illustrations
OUCH
https://icons8.com/illustrations
Icons
Font Awesome
https://fontawesome.com/
Material Icons
https://fonts.google.com/icons
Flaticon
https://flaticon.com/
Heroicons
https://heroicons.com/
Freelancing
Upwork
https://upwork.com/
Freelancer
https://freelancer.com/
Fiverr
https://fiverr.com/
Toptal
https://toptal.com/
Hosting
Netlify
https://netlify.com/
Vercel
https://vercel.com/
GitHub Pages
https://pages.github.com/
Firebase
https://firebase.google.com/
Challenges
The developer’s life is a life of challenges (& bugs,
haha). To keep up with trends, we have to
challenge ourselves constantly. For that, use:
CSS Battle
Battleground to improve, tighten CSS skills
https://cssbattle.dev/
Frontend Mentor
Develop, practice & compete to code a
frontend website from its design file.
https://frontendmentor.io/
Guides
Covers valuable cheat sheets, guides and great
tutorials on tech stuff.
DevDocs
Pragmatic information on almost every
language.
https://devdocs.io/
DevHints
Beautiful cheatsheets comprising many
languages.
https://devhints.io/
Guides
GitSheets
A dead simple git cheatsheet.
https://gitsheet.wtf/
30secondsofcode
Provides short code snippet mainly featuring
JavaScript.
https://30secondsofcode.org/
OverAPI
A site collecting all the cheatsheets, all!
https://overapi.com/
Tools
Many prominent developers have created
excellent, crazy tools to boost development.
These are some of them:
Remove BG
An AI tool to help remove the background of an
image in 5 seconds with just one click.
https://remove.bg/
Clippy
Creates complex shapes in CSS using clip-path
property like (circle, ellipse, polygon, or inset),
https://bennettfeely.com/clippy/
Tools
Haikei
Generates unique SVG design assets
https://haikei.app/
https://webcode.tools/
Transform
A polyglot web converter.
https://transform.tools/
The End.
Congratulations!
You've made it to the end.
https://jsmastery.pro