APWT02
APWT02
MD. AL-AMIN
Table of Contents
1. Variables
2. Data Types
3. Arrays
4. Functions
5. Control Flow
6. Classes & Objects
7. Operators
8. Template Literals
9. Asynchronous JavaScript
10. Destructure
11. Concept of Modules
12. Closures and Scope
Variables
Variables are used to store data in a program. JavaScript has three types of
variable declarations: var, let, and const.
Variables
● var: Variables declared with var are function-scoped,
meaning they are limited to the function in which they
are declared. If declared outside any function, they
become globally scoped. var can be reassigned and
updated.
Data types include primitive types like strings, numbers, booleans, null, and undefined, as well as
objects.
String: Represents a sequence of
characters.
Collections of elements can be stored and managed using arrays in JavaScript. Square brackets are used to
form arrays, which can hold a variety of data types, such as objects, strings, numbers, and other arrays.
Arrays
Array Iteration:
forEach(): Performs a given function once for every element in the array.
Cod Outp
e ut
Arrays
map(): Calls a function on each element, creating a new array containing the results.
Cod Outp
e ut
Arrays
filter(): The filter() method is used to create a new array with elements that pass a
specific test provided by a function. It does not modify the original array but returns a new
array containing only the elements that satisfy the specified condition.
Functions
Functions are reusable code blocks that are created to carry out particular tasks.
Functions
Function Return: JavaScript will "return"
to run the code after the invoking
statement if the function was called from a
statement.
Difference between while and do-while loop: The body of a while loop will never be
executed if the condition is originally false. Regardless of the starting condition, the body
of the loop is run at least once in a do-while loop.
Control Flow
for…in for…of
The order of iterations may differ and is not It ensures that the iteration order is well-
guaranteed. defined and consistent, taking into account
the internal structure of the iterable.
When working with objects when it is When working with iterable objects—arrays,
needed to repeatedly access their keys or strings, maps, sets, etc.—and needing to
properties loop through their values.
Classes & Objects
Classes in JavaScript offer a more streamlined and grammatical method for defining object-oriented
programming structures.
Class Declaration: The “class” keyword and the class name are used to declare a class. When an object is instantiated
from a class, a particular method called the constructor method is invoked. It is applied to initialise properties of objects.
Classes & Objects
Class Methods: Class methods are functions that are defined within a class.
Objects: Objects (instances) of a class are created using the new keyword.
Classes & Objects
Inheritance: Classes can inherit properties and methods from other classes using the extends keyword.
Classes & Objects
Object Methods: Object.keys, Object.values, Object.entries - these methods allow you to work
with object keys, values, and entries.
Operators
JavaScript includes a variety of operators, which are symbols or keywords that perform
operations on operands.
Cod Outp
e ut
Operators
Spread Operator (...): The spread operator is used to expand elements of an array or object.
Operators
Rest Parameter (...): The rest parameter is used to collect the remaining arguments of a function into a single
array.
Template Literal
Template Literal is also known as “String Templates” and “Template Strings”. Template
literals offer a more practical and adaptable method of working with strings. Template
Strings use backticks (``) rather than the quotes ("") to define a string.
Template Literal
Cod Outp
e ut
Template Literal
String Interpolation: Interpolating variables and expressions into strings is made simple with the
help of Template Strings.
Asynchronous JavaScript
Asynchronous JavaScript is a programming paradigm that allows code execution to continue while
waiting for specific operations to complete, rather than stopping execution until those operations
are completed. Asynchronous operations are critical in situations when processes such as
retrieving data from a server, reading a file, or waiting for user input may take some time.
Asynchronous JavaScript
Promises: Promises are objects that reflect the eventual success or failure of an
asynchronous action.
Async/Await: Async and await make promises easier to write. Async causes a
function to return a promise. Await causes a function to wait for a promise.
Destructuring
Array
Destructure
Destructuring
Objects
Destructure
Destructuring function
parameters
Concept of Modules
Closures and scope are basic notions in JavaScript that determine how variables and
functions are defined, accessed, and preserved throughout the code.
Scopes: Scope refers to the context in which variables and functions are declared, which
determines their accessibility.
Global Scope:
Closures:
1. https://www.w3schools.com/js/
2. https://devdocs.io/javascript/
3. ESLint
4. Prettier - Code Formatter
5. GitLens
6. npm Intellisense
7. Live Server
Thank You