Skip to content

Commit

Permalink
chore: Update table of contents in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
manthanank committed Jun 27, 2024
1 parent 8166d83 commit 5d7c50b
Showing 1 changed file with 107 additions and 13 deletions.
120 changes: 107 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This repository contains a list of JavaScript concepts, functions, methods, and

![GitHub](https://img.shields.io/github/license/manthanank/learn-javascript)

## Contents
## Table of Contents

- [Introduction](#introduction)
- [Add JavaScript](#add-javascript)
Expand Down Expand Up @@ -279,10 +279,24 @@ const c = 1; // Declare a read-only variable z with the value 15 (block-level sc

## Data Types

There are two types of data types in JavaScript:

- **Primitive Data Types**
- **Non-Primitive Data Types**

### 1. Primitive Data Types

**Primitive data types** are the most basic data types in JavaScript. They are immutable (cannot be changed) and are copied by value.

**Primitive data types** include:

- **numbers**
- **strings**
- **booleans**
- **null**
- **undefined**
- **symbol**

**numbers** -

```javascript
Expand Down Expand Up @@ -322,6 +336,15 @@ let a = Symbol();

### 2. Non Primitive Data Types

**Non-primitive data types** are complex data types that are mutable (can be changed) and are copied by reference.

**Non-primitive data types** include:

- **objects**
- **arrays**
- **functions**
- **regexp**

**functions** -

```javascript
Expand Down Expand Up @@ -356,10 +379,26 @@ Example
let pattern = /w3schools/i;
```

[Back to Top⤴️](#table-of-contents)

## Operators

Operators are used to perform operations on variables and values.

There are different types of operators in JavaScript:

- **Arithmetic Operators**
- **Logical Operators**
- **Comparison Operators**
- **Bitwise Operators**
- **Type Operators**
- **Assignment Operators**
- **Conditional (Ternary) Operator**
- **Nullish Coalescing Operator(??)**
- **Optional Chaining Operator(?.)**
- **delete Operator**
- **Spread (...) Operator**

### Arithmetic Operators

| Operator | Description |
Expand Down Expand Up @@ -633,6 +672,8 @@ let numbers = [1, 2, 3];
console.log(sum(...numbers)); // Output: 6
```
[Back to Top⤴️](#table-of-contents)
## Boolean
JavaScript booleans can have one of two values: true or false.
Expand Down Expand Up @@ -679,6 +720,8 @@ let value = true;
console.log(value.valueOf()); // Output: true
```
[Back to Top⤴️](#table-of-contents)
## Object
Objects are used to store key/value (name/value) collections.
Expand Down Expand Up @@ -752,6 +795,8 @@ let person = {
console.log(person.valueOf()); // Output: {firstName: "Manthan", lastName: "Ank"}
```
[Back to Top⤴️](#table-of-contents)
## Arrays
Arrays are used to store multiple values in a single variable.
Expand All @@ -764,6 +809,30 @@ const letters = ['a', 'b', 'c'];
The following are some of the most commonly used array methods in JavaScript:
- **concat()**
- **constructor**
- **copyWithin()**
- **entries()**
- **every()**
- **fill()**
- **filter()**
- **find()**
- **findIndex()**
- **forEach()**
- **from()**
- **includes()**
- **indexOf()**
- **isArray()**
- **join()**
- **keys()**
- **lastIndexOf()**
- **length**
- **map()**
- **pop()**
- **prototype**
- **push()**
- **reduce()**
**concat()** - Joins arrays and returns an array with the joined arrays
It is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array that contains the values of the original arrays.
Expand Down Expand Up @@ -874,9 +943,13 @@ array.forEach(value => {
**from()** - Creates an array from an object
```javascript
let array = Array.from('hello');
let array = 'hello';

let newArray = Array.from(array);

console.log(array); // Output: "hello"

console.log(array); // Output: ["h", "e", "l", "l", "o"]
console.log(newArray); // Output: ["h", "e", "l", "l", "o"]
```
**includes()** - Check if an array contains the specified element
Expand All @@ -886,7 +959,10 @@ let array = [1, 2, 3, 4, 5];

let result = array.includes(3);

console.log(array); // Output: [1, 2, 3, 4, 5]

console.log(result); // Output: true
console.log(array.includes(6)); // Output: false
```
**indexOf()** - Search the array for an element and returns its position
Expand All @@ -896,7 +972,10 @@ let array = [1, 2, 3, 4, 5];

let index = array.indexOf(3);

console.log(array); // Output: [1, 2, 3, 4, 5]

console.log(index); // Output: 2
console.log(array.indexOf(6)); // Output: -1
```
**isArray()** - Checks whether an object is an array
Expand All @@ -906,7 +985,10 @@ let array = [1, 2, 3, 4, 5];

let result = Array.isArray(array);

console.log(array); // Output: [1, 2, 3, 4, 5]

console.log(result); // Output: true
console.log(Array.isArray('hello')); // Output: false
```
**join()** - Joins all elements of an array into a string
Expand All @@ -916,6 +998,8 @@ let array = ['a', 'b', 'c'];

let result = array.join();

console.log(array); // Output: ["a", "b", "c"]

console.log(result); // Output: "a,b,c"
```
Expand All @@ -926,6 +1010,8 @@ let array = ['a', 'b', 'c'];

let iterator = array.keys();

console.log(array); // Output: ["a", "b", "c"]

console.log(iterator.next().value); // Output: 0
```
Expand All @@ -936,6 +1022,8 @@ let array = [1, 2, 3, 4, 5, 3];

let index = array.lastIndexOf(3);

console.log(array); // Output: [1, 2, 3, 4, 5, 3]

console.log(index); // Output: 5
```
Expand All @@ -944,6 +1032,8 @@ console.log(index); // Output: 5
```javascript
let array = ['a', 'b', 'c'];

console.log(array); // Output: ["a", "b", "c"]

console.log(array.length); // Output: 3
```
Expand All @@ -954,6 +1044,8 @@ let array = [1, 2, 3, 4, 5];

let newArray = array.map(value => value * 2);

console.log(array); // Output: [1, 2, 3, 4, 5]

console.log(newArray); // Output: [2, 4, 6, 8, 10]
```
Expand All @@ -964,31 +1056,31 @@ let array = ['a', 'b', 'c'];

let element = array.pop();

console.log(array); // Output: ["a", "b"]

console.log(element); // Output: "c"
```
**prototype** - Allows you to add properties and methods to an Array object
```javascript
Array.prototype.sum = function() {
let total = 0;
for (let i = 0; i < this.length; i++) {
total += this[i];
}
return total;
};
let array = ['a', 'b', 'c'];

let array = [1, 2, 3, 4, 5];
Array.prototype.age = 25;

console.log(array); // Output: ["a", "b", "c"]

console.log(array.sum()); // Output: 15
console.log(array.age); // Output: 25
```
**push()** - Adds new elements to the end of an array, and returns the new length
```javascript
let array = ['a', 'b', 'c'];

let length = array.push('d');
let length = array.push('d', 'e');

console.log(array); // Output: ["a", "b", "c", "d", "e"]

console.log(length); // Output: 4
```
Expand All @@ -1000,6 +1092,8 @@ let array = [1, 2, 3, 4, 5];

let total = array.reduce((accumulator, value) => accumulator + value, 0);

console.log(array); // Output: [1, 2, 3, 4, 5]

console.log(total); // Output: 15
```
Expand Down

0 comments on commit 5d7c50b

Please sign in to comment.