0% found this document useful (0 votes)
11 views

Data Structure in Js

Uploaded by

vmusale908
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Data Structure in Js

Uploaded by

vmusale908
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

ES6 is a series of new features added to the JavaScript.

In ES6 version includes new collections of


data types, so there’s no longer a need to use objects and it is easier to implement things in a simple
way.
In ES6 version two new things are introduced in JavaScript.

 Map
 Sets

Maps: Maps are collections of keys and values of any type, in simple word Map is a collection
of key-value pairs. It works like an object in JavaScript. It returns a new or empty map.
Syntax: var map = new Map();

Methods Description

map.size() It determines the number of key or values in the map.

It sets the value for the key .It takes two parameters, key and the value for the
map.set() key.

map.has() It checks whether a key is present in the map or not then its returns true.

It takes a value associated with a key .If the value is not available then its
map.get() undefined.

map.keys() It returns an iterator for all the keys in the map.

It returns a new iterator array of which contains key-value pair for each
map.entries() element by insertion order.

map.values() It returns an iterator for each of the values in the map.

map.delete() It is used to delete an entry.

map.clear() It clears all key-value pairs from the map.

map.forEach( It executes the callback function once. This function executed for each element
) in the map.
Here's a detailed explanation of the methods for Map:

1. map.size:
o Description: Returns the number of key-value pairs in the map.
o Example:

let map = new Map();

map.set('name', 'John');

map.set('age', 30);

console.log(map.size); // Output: 2

2. map.set(key, value): Description: Sets a value for a specific key in the map. It takes two
parameters: the key and the value.

Example:
let map = new Map();

map.set('city', 'New York');

console.log(map.get('city')); // Output: New York

3. map.has(key):
o Description: Checks whether a specific key exists in the map. Returns true if the key
is present, otherwise false.
o Example:

let map = new Map();

map.set('country', 'USA');

console.log(map.has('country')); // Output: true

console.log(map.has('state')); // Output: false

4. map.get(key):
o Description: Retrieves the value associated with a specific key. Returns undefined if
the key is not present.
o Example:

let map = new Map();

map.set('name', 'Alice');

console.log(map.get('name')); // Output: Alice

console.log(map.get('age')); // Output: undefined

5. map.keys():
o Description: Returns an iterator containing all the keys in the map.
o Example:

let map = new Map([['name', 'John'], ['age', 25]]);

for (let key of map.keys()) {

console.log(key); // Output: 'name', 'age'

6. map.entries():
o Description: Returns an iterator containing key-value pairs for each element in the
map, in insertion order.
o Example:

let map = new Map([['color', 'blue'], ['size', 'large']]);

for (let [key, value] of map.entries()) {


console.log(key + ': ' + value); // Output: color: blue, size: large

7. map.values():
o Description: Returns an iterator for all values in the map, in insertion order.
o Example:

let map = new Map([['name', 'John'], ['age', 30]]);

for (let value of map.values()) {

console.log(value); // Output: John, 30

8. map.delete(key):
o Description: Removes the entry associated with the specified key from the map.
Returns true if the key existed and was deleted, otherwise false.
o Example:

let map = new Map();

map.set('city', 'New York');

console.log(map.delete('city')); // Output: true

console.log(map.has('city')); // Output: false

9. map.clear():
o Description: Removes all key-value pairs from the map.
o Example

let map = new Map();

map.set('name', 'John');

map.set('age', 25);

map.clear();

console.log(map.size); // Output: 0

10. map.forEach(callback):
o Description: Executes a callback function for each key-value pair in the map. The
callback function takes three arguments: value, key, and the map itself.
o Example:

let map = new Map();

map.set('name', 'John');
map.set('age', 25);

map.forEach((value, key) => {

console.log(key + ': ' + value);

});

// Output:

// name: John

// age: 25

The map.forEach() method is used to execute a callback function once for each key-value pair in a
Map. It iterates over each element in the Map in the order in which the elements were inserted.

Key Points:

 Arguments of the callback function:


o value: The value of the current entry in the map.
o key: The key of the current entry in the map.
o map: The entire Map object itself (optional, rarely used).

How forEach Works:

 The forEach() method loops over each key-value pair in the Map, calling the provided
callback function.
 The callback receives three arguments for each iteration:
1. The value stored in the current entry.
2. The key corresponding to that value.
3. The Map itself (optional; useful if you want to reference the entire Map inside the
callback).
 The iteration is done in insertion order. So, the first key-value pair added to the map will be
processed first.
 These methods make Map a powerful and flexible data structure for working with key-value
pairs in JavaScript.

Example 2: Using all three arguments (value, key, map)


let map = new Map([
['name', 'Alice'],
['age', 30],
['city', 'Paris']
]);

map.forEach((value, key, map) => {


console.log(key + ' = ' + value);
console.log('Map size:', map.size);
});
Example 3: Modifying the value inside forEach

let map = new Map();


map.set('name', 'John');

map.set('age', 25);

map.forEach((value, key, map) => {

if (key === 'age') {

map.set('age', value + 5); // Modify the value of the age

});

console.log(map.get('age')); // Output: 30

2. WeakMap

A WeakMap is similar to Map, but with two main differences:

 The keys must be objects, not primitive values.


 The references to keys in a WeakMap are "weak," meaning if no other references to the key
object exist, it can be garbage-collected.

Features:

 No size property (as keys may be garbage-collected).


 Only object keys are allowed.
 Useful for associating private data with objects without preventing garbage collection.

Implementation Example:

// Create a new WeakMap

let weakMap = new WeakMap();

// Create objects to use as keys

let obj1 = { name: 'Object 1' };

let obj2 = { name: 'Object 2' };

// Add object key-value pairs

weakMap.set(obj1, 'Info for Object 1');


weakMap.set(obj2, 'Info for Object 2');

// Retrieve values by object keys

console.log(weakMap.get(obj1)); // Output: Info for Object 1

// Check if a key exists

console.log(weakMap.has(obj2)); // Output: true

// Remove a reference

obj1 = null; // obj1 can now be garbage-collected since WeakMap holds a weak reference

// obj1 will no longer exist in the WeakMap

Use Case:

 WeakMap is ideal when you want to associate metadata with objects without preventing them
from being garbage-collected. This makes it perfect for scenarios such as caching objects or
storing metadata about DOM nodes.

3 What is a Set?
A Set is a collection of unique values in JavaScript, introduced in ES6
(ECMAScript 2015). Unlike arrays, Sets do not allow duplicate values,
which means every value in a Set appears only once.
Key Characteristics of Set:
 Uniqueness: No duplicates are allowed.
 Mutability: A set is mutable, meaning you can add and remove
elements.
 Order of Elements: The elements are ordered based on their
insertion order (just like arrays).
 Objects and Primitives: A Set can store both primitive values (like
strings, numbers) and objects.

Methods Description
set.size() It returns the total number of values present in the set.
set.add() It adds a value to the set if the value was not already in
the set.
set.clear() It removes all values from the set
It removes one value from the set, the value is passed as
set.delete(v) argument.
If the passed value “v” is in the set, then this method
set.has(v) returns true.
It returns an iterator object which contains an array
set.entries() having the entries of the set.
set.values() and They both are returns all the values from the Set, similar
set.keys() to map.values().
It same as map.forEach() ,it executes the callback
set.forEach() function once. This function executed for each element in
method the set.

Creating a Set:

You can create a Set like this:

let mySet = new Set();

Or, you can initialize it with an array (duplicates will automatically be removed):

let mySet = new Set([1, 2, 3, 4, 4, 5]); // Duplicate 4 will be ignored

console.log(mySet); // Output: Set { 1, 2, 3, 4, 5 }

Methods of Set

1. set.size:
o Description: Returns the total number of unique values present in the Set.

let mySet = new Set([1, 2, 3, 4]);

console.log(mySet.size); // Output: 4

2. set.add(value):
o Description: Adds a new value to the Set if it’s not already present. If the value is
already in the Set, it will not be added again.
o Example:

let mySet = new Set();

mySet.add(1);
mySet.add(2);

mySet.add(1); // Duplicate value, will not be added

console.log(mySet); // Output: Set { 1, 2 }

3. set.clear():
o Description: Removes all values from the Set, making it empty.
o Example:

let mySet = new Set([1, 2, 3]);

mySet.clear();

console.log(mySet.size); // Output: 0

4. set.delete(value):
o Description: Removes a specific value from the Set. Returns true if the value was
present and deleted, and false otherwise.
o Example:

let mySet = new Set([1, 2, 3]);

mySet.delete(2);

console.log(mySet); // Output: Set { 1, 3 }

5. set.has(value):
o Description: Checks whether a specific value is present in the Set. Returns true if the
value is found, otherwise false.
o Example:

let mySet = new Set([1, 2, 3]);

console.log(mySet.has(2)); // Output: true

console.log(mySet.has(4)); // Output: false

6. set.entries():
o Description: Returns an iterator object containing an array of [value, value] for each
element in the Set (similar to Map.entries()). Since Set doesn’t have keys, both
elements in the array are the same.
o Example:

let mySet = new Set([1, 2, 3]);

for (let entry of mySet.entries()) {

console.log(entry); // Output: [1, 1], [2, 2], [3, 3]

}
7. set.values() and set.keys():
o Description: Both set.values() and set.keys() return an iterator over the values of the
Set. Since a Set doesn't have keys (like a Map), these two methods are functionally
the same.
o Example:

let mySet = new Set([1, 2, 3]);

for (let value of mySet.values()) {

console.log(value); // Output: 1, 2, 3

for (let key of mySet.keys()) {

console.log(key); // Output: 1, 2, 3 (same as values)

8. set.forEach(callback):
o Description: Executes the provided callback function once for each element in the
Set, in the order they were inserted. The callback function receives three arguments:
 value: The current value being processed in the Set.
 valueAgain: Same as the first argument (because there are no keys in a Set).
 set: The entire Set object.
o Example:

let mySet = new Set([1, 2, 3]);

mySet.forEach((value) => {

console.log(value);

});

// Output: 1, 2, 3

Example of Using Multiple Methods:

let mySet = new Set([1, 2, 3, 4]);

// Add a value

mySet.add(5);

// Check if a value exists

console.log(mySet.has(3)); // Output: true


// Get the size of the set

console.log(mySet.size); // Output: 5

// Iterate using forEach

mySet.forEach((value) => {

console.log(value); // Output: 1, 2, 3, 4, 5

});

// Delete a value

mySet.delete(4);

console.log(mySet); // Output: Set { 1, 2, 3, 5 }

// Clear all values

mySet.clear();

console.log(mySet.size); // Output: 0

Summary:

 Set is a collection of unique values, meaning duplicates are automatically ignored.


 Set offers methods to add, remove, and check values (add, delete, has, clear).
 It also provides methods for iteration (forEach, values, keys, entries).
 Set can be very useful when you need to maintain a list of unique items without duplication.

4. WeakSet: A WeakSet is similar to Set, but with some important differences: The elements must
be objects. References to objects in a WeakSet are weak, so if no other references exist to an object, it
can be garbage-collected

A WeakSet in JavaScript is a special type of set that, like a regular Set, holds a collection of unique
values. However, it has some important differences that make it suitable for specific use cases,
especially when memory management and object lifecycle are important.

Key Characteristics of WeakSet:

1. Only Objects as Values:


o Unlike a Set, where you can store any type of value (primitives or objects), a WeakSet
can only store object references. You cannot store primitive values like numbers,
strings, or booleans in a WeakSet.
2. Weak References:
o References to objects in a WeakSet are "weak," meaning the presence of an object in
a WeakSet does not prevent it from being garbage-collected if there are no other
references to that object in your program.
o This is different from a Set, where values are strongly referenced, so they stay in
memory as long as the Set exists.
3. No Iteration or Size Property:
o Unlike Set, a WeakSet does not have a size property or any way to iterate over its
elements. This is because the elements can be garbage-collected, and the structure of
the WeakSet is not predictable in terms of content over time.
o You cannot use methods like forEach(), values(), or entries() with a WeakSet.
4. Non-enumerability:
o You cannot loop through or list all the elements of a WeakSet like you can with a
regular Set. This is because, due to the weak references, the content of the WeakSet
can change automatically when objects are garbage-collected.

Features of WeakSet:

 Garbage Collection: If an object inside a WeakSet has no other references in the program, it
can be garbage-collected automatically. This makes WeakSet useful for memory management
purposes, as you don't have to manually remove objects from it when they're no longer
needed.
 No Duplicates: Like a regular Set, a WeakSet does not allow duplicate objects. If you try to
add the same object twice, it will be stored only once.

Use Cases:

The main use case for WeakSet is when you need to track objects without preventing them from being
garbage-collected. This can be useful in scenarios where objects are temporary or only need to be
remembered while they are in use elsewhere in the program.

WeakSet Methods:

Since a WeakSet cannot be iterated over and does not store primitive values, it has fewer methods
than a regular Set.

1. weakSet.add(value):
o Description: Adds an object to the WeakSet. If the object is already in the set, it is
ignored (i.e., no duplicates).
o Example:

let obj1 = { name: "Alice" };

let obj2 = { name: "Bob" };

let weakSet = new WeakSet();

weakSet.add(obj1);

weakSet.add(obj2);

console.log(weakSet)

2. weakSet.has(value):
o Description: Checks if the specified object is in the WeakSet. Returns true if the
object is found, and false otherwise.
o Example:

console.log(weakSet.has(obj1)); // Output: true


console.log(weakSet.has({ name: "Alice" })); // Output: false, different object reference

3. weakSet.delete(value):
o Description: Removes the specified object from the WeakSet. If the object was
successfully removed, it returns true. If the object was not in the set, it returns false.
o Example:

weakSet.delete(obj1);

console.log(weakSet.has(obj1)); // Output: false, obj1 has been removed

Example of WeakSet in Action:

let weakSet = new WeakSet();

let obj1 = { name: "Alice" };

let obj2 = { name: "Bob" };

weakSet.add(obj1);

weakSet.add(obj2);

console.log(weakSet.has(obj1)); // Output: true

weakSet.delete(obj2);

console.log(weakSet.has(obj2)); // Output: false

Understanding Garbage Collection in WeakSet:

The unique feature of WeakSet is that the objects inside it are weakly referenced. This means if there
are no other references to an object stored in the WeakSet, the JavaScript engine will automatically
remove it from memory (garbage collection).

For example:

let weakSet = new WeakSet();

let obj = { name: "Alice" };

weakSet.add(obj);

console.log(weakSet.has(obj)); // Output: true

obj = null; // The object is now eligible for garbage collection

In this code, once obj is set to null, it is no longer referenced by any variable. Because the WeakSet
holds a weak reference to obj, the object is eligible for garbage collection and will be removed from
memory automatically when needed.

Important Differences Between Set and WeakSet:


Feature Set WeakSet
Can hold any type (primitives or
Values Can only hold objects
objects)
Garbage Objects stay in the Set until Objects are garbage-collected if there are no
Collection manually removed other references
Size Property Has a size property No size property
Iteration Can iterate (e.g., forEach()) Cannot iterate (no forEach(), values(), etc.)
Duplicates No duplicates allowed No duplicates allowed
Summary:

 A WeakSet is like a Set, but it can only store objects (not primitives), and it holds weak
references to those objects.
 If no other part of the program references an object in a WeakSet, that object will be
automatically garbage-collected.
 WeakSet does not provide methods to iterate through its contents, nor does it have a size
property, making it less predictable but more memory-efficient in some cases.

WeakSet is particularly useful for memory-sensitive scenarios, where you need to keep track of
objects without preventing them from being garbage-collected.

Structure Data (JSON):

JSON stands for JavaScript Object Notation

JSON is a text format for storing and transporting data

JSON is "self-describing" and easy to understand

 JSON is a lightweight data-interchange format


 JSON is plain text written in JavaScript object notation
 JSON is used to send data between computers
 JSON is language independent *

The JSON format is syntactically similar to the code for creating JavaScript objects. Because of this, a
JavaScript program can easily convert JSON data into JavaScript objects.

JavaScript has a built in function for converting JSON strings into JavaScript objects:

JSON.parse()

JavaScript also has a built in function for converting an object into a JSON string:

JSON.stringify()

JSON Syntax Rules

JSON syntax is derived from JavaScript object notation syntax:

 Data is in name/value pairs


 Types of Values:
 Array: An associative array of values.
 Boolean: True or false.
 Number: An integer.
 Object: An associative array of key/value pairs.
 String: Several plain text characters which usually form a word
 Data is separated by commas

{ "name":"Thanos", "Occupation":"Destroying half of humanity" }

Curly braces hold objects

let person={ "name":"Thanos", "Occupation":"Destroying half of humanity" }

Square brackets hold arrays

let person={ "name":"Thanos", "Occupation":"Destroying half of humanity", "powers": ["Can destroy


anything with snap of his fingers", "Damage resistance", "Superhuman reflexes"] }

console.log(person);

Characteristics of JSON

 Human-readable and writable: JSON is easy to read and write.

 Lightweight text-based data interchange format: JSON is simpler to read and write
when compared to XML.

 Widely used: JSON is a common format for data storage and communication on the
web.

 Language-independent: Although derived from JavaScript, JSON can be used with


many programming languages.

JSON Objects
A JSON object is a collection of key/value pairs. The keys are strings, and the values can
be strings, numbers, objects, arrays, true, false, or null.
JSON Arrays
A JSON array is an ordered collection of values. The values can be strings, numbers,
objects, arrays, true, false, or null.
Convert a JSON Text to a JavaScript Object

To convert JSON text into a JavaScript object, you can use the JSON.parse() method as
shown in the example above. This method parses the JSON string and constructs the
JavaScript value or object described by the string.

We will see how to convert a JSON text into a JavaScript Object.

Example: We will be using the JSON.parse() method to convert the JSON text to a
JavaScript Object

let text = '{"model":[' +


'{"carName":"Baleno","brandName":"Maruti" },' +

'{"carName":"Aura","brandName":"Hyndai" },' +

'{"carName":"Nexon","brandName":"Tata" }]}';

const cars = JSON.parse(text);

console.log(cars);

const cars=JSON.stringify(text);

console.log("The car name is: " + cars.model[2].carName +

" of brand: " + cars.model[2].brandName);

Indexed collections in JavaScript refer to data structures like arrays, where elements are
stored and accessed by numerical indices. Arrays allow for efficient storage and retrieval of
ordered data, providing methods for manipulation and traversal of their elements.

Example

an array called ‘student’ contains the names of the students and the index values are the
Roll Numbers of the students. JavaScript does not have an explicit array data type. However,
we can use the predefined Array object in JavaScript and its methods to work with arrays.

Creating an Array: There are many ways to create and initialize an array that is listed
below:

Creating arrays without defining the array length. In this case, the length is equal to the
number of arguments.

Syntax:

let arr = new Array( element0, element1, ... );

let arr = Array( element0, element1, ... );

let arr = [ element0, element1, ... ];

Creating an array with the given size

Syntax:

let arr = new Array(6);


let arr = Array(6);

let arr = [];

arr.length = 6;

Create a variable-length array and add many elements as you need.

// First method: Initialize an empty

// array then add elements

let students = [];

students [0] = 'Sujata Singh';

students [1] = 'Mahesh Kumar';

students [2] = 'Leela Nair';

// Second method: Add elements to

// an array when you create it

let fruits = ['apple', ‘mango', 'Banana'];

The methods that can be applied over arrays are:

Accessing the Array Elements

Obtaining array length

Iterating over arrays

JavaScript for loop

JavaScript forEach() Loop

JavaScript forEach Loop with Arrow Functions

Array Methods

JavaScript push() Method

JavaScript pop() Method


JavaScript concat() Method

JavaScript join() Method

JavaScript sort() Method

JavaScript indexOf() Method

JavaScript shift() Method

JavaScript filter() Method

Accessing the Array Elements

Use indices to access array elements. Indices of Arrays are zero-based which means the index
of the elements begins with zero.

javascript

let fruits = ['Apple', 'Mango', 'Banana'];

console.log(fruits [0]);

console.log(fruits[1]);

Output

Apple

Mango

Obtaining array length

To obtain the length of an array use array_name.length property.

javascript

let fruits = ['Apple', 'Mango', 'Banana'];

console.log(fruits.length)

Output

Iterating over arrays

There are many ways to iterate the array elements.


JavaScript for loop: for loop provides a concise way of writing the loop structure. Unlike a
while loop, a for statement consumes the initialization, condition, and increment/decrement in
one line thereby providing a shorter, easy-to-debug structure of looping.

javascript

const fruits = ['Apple', 'Mango', 'Banana'];

for (let i = 0; i < fruits.length; i++) {

console.log(fruits[i]);

Output

Apple

Mango

Banana

JavaScript forEach() Loop: The forEach() function provides once for each element of the
array. The provided function may perform any kind of operation on the elements of the given
array.

javascript

const fruits = ['Apple', 'Mango', 'Banana'];

fruits.forEach(function (fruit) {

console.log(fruit);

});

Output

Apple

Mango

Banana

JavaScript forEach Loop with Arrow Functions:

javascript
const fruits = ['Apple', 'Mango', 'Banana'];

fruits.forEach(fruit => console.log(fruit));

Output

Apple

Mango

Banana

Array Methods

There are various array methods available to us for working on arrays. These are:

JavaScript push() Method: This method adds one or more elements to the end of an array
and returns the resulting length of the array.

javascript

let numbers = new Array('1', '2');

numbers.push('3');

console.log(numbers);

Output

[ '1', '2', '3' ]

JavaScript pop() Method: This method removes the last element from an array and returns
that element.

javascript

let numbers = new Array('1', '2', '3');

let last = numbers.pop();

console.log(last);

Output

JavaScript concat() Method: This method joins two arrays and returns a new array.
javascript

let myArray = new Array('1', '2', '3');

myArray = myArray.concat('a', 'b', 'c');

console.log(myArray);

Output

[ '1', '2', '3', 'a', 'b', 'c' ]

JavaScript join() Method: This method creates a string by joining all the elements of an
array.

javascript

let students = new Array('john', 'jane', 'joe');

let list = students.join(' - ');

console.log(list);

Output

john - jane - joe

JavaScript sort() Method: This method sorts the elements of an array.

javascript

let myArray = new Array('West', 'East', 'South');

myArray.sort();

console.log(myArray);

Output

[ 'East', 'South', 'West' ]

JavaScript indexOf() Method: This method searches the array for an Element and returns
the index of the first occurrence of the element.

javascript

let myArr = ['a', 'b', 'a', 'b', 'a'];


console.log(myArr.indexOf('b'));

Output

JavaScript shift() Method: This method removes the first element from an array and returns
that element.

javascript

let myArr = new Array('a', 'b', 'c');

let first = myArr.shift();

console.log(first);

Output

JavaScript reverse() Method: This method reverses the first array element become the last
and the last becomes the first. It transposes all the elements in an array in this manner and
returns a reference to the array.

javascript

let myArr = new Array('a', 'b', 'c');

myArr.reverse();

console.log(myArr);

Output

[ 'c', 'b', 'a' ]

JavaScript map() Method: This method returns a new array of the returned value from
executing a function on every array item.

javascript

let myArr1 = ['a', 'b', 'c'];

let a2 = myArr1.map(function (item) {

return item.toUpperCase();
});

console.log(a2);

Output

[ 'A', 'B', 'C' ]

JavaScript filter() Method: This method returns a new array containing the items for which
the function returned true.

javascript

let myArr1 = ['a', 10, 'b', 20, 'c', 30];

let a2 = myArr1.filter(function (item) {

return typeof item === 'number';

});

console.log(a2);

Output

[ 10, 20, 30 ]

Typed Arrays:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Typed_arrays#views

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/
TypedArray

Equality Comparisons:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/
Equality_comparisons_and_sameness

Loops and Iterations:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration

label statement: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/


Statements/label
conditional Statement:

https://www.javascript.com/learn/conditionals#:~:text=Conditional%20statements
%20control%20behavior%20in,for%20a%20block%20of%20code.

if else:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else

switch:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch

throw:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw

try/catch/finally:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/
try...catch

Expressions and Operators: next pdf

You might also like