Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #49

Closed
wants to merge 2 commits into from
Closed

Dev #49

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/dsa/dsa.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
id: dsa
title: Data Structures and Algorithms
sidebar_label: DSA
sidebar_position: 1
---

202 changes: 202 additions & 0 deletions docs/javascript/objects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
---
id: objects-in-javascript
title: Objects in JavaScript
sidebar_label: Objects
sidebar_position: 16
tags: [JavaScript]
description: "In this tutorial, we will learn about objects in JavaScript. We will learn how to create objects, access object properties, and methods. We will also learn about object destructuring, object methods, and object prototypes."
---

In JavaScript, an object is a standalone entity, with properties and type. It is a collection of key-value pairs. The keys are strings and the values can be anything. An object can be created using object literal or constructor function.

## Creating Objects

There are two ways to create objects in JavaScript:

1. **Object Literal**: The object literal is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces `{}`.
2. **Constructor Function**: The constructor function is used to create an object. It is a function that is used to create an object.

### Object Literal

The object literal is the easiest way to create an object. It is a list of zero or more pairs of property names and associated values of an object, enclosed in curly braces `{}`.

Here's an example of creating an object using object literal:

```js title="app.js"
// Creating an object using object literal
let person = {
name: 'John Doe',
age: 30,
email: '[email protected]',
greet: function() {
return `Hello, my name is ${this.name}`;
}

};

console.log(person.name); // John Doe
console.log(person.age); // 30
console.log(person.email); // [email protected]
console.log(person.greet()); // Hello, my name is John Doe
```

In the above example, we have created an object `person` using object literal. The object has properties `name`, `age`, `email`, and a method `greet`.

### Constructor Function

The constructor function is used to create an object. It is a function that is used to create an object.

Here's an example of creating an object using constructor function:

```js title="app.js"
// Creating an object using constructor function
function Person(name, age, email) {
this.name = name;
this.age = age;
this.email = email;
this.greet = function() {
return `Hello, my name is ${this.name}`;
};
}

let person = new Person('John Doe', 30, '[email protected]');

console.log(person.name); // John Doe
console.log(person.age); // 30
console.log(person.email); // [email protected]
console.log(person.greet()); // Hello, my name is John Doe
```

In the above example, we have created an object `person` using constructor function `Person`. The constructor function `Person` takes three parameters `name`, `age`, and `email` and assigns them to the object properties.

## Accessing Object Properties

You can access the properties of an object using dot notation or bracket notation.

### Dot Notation

You can access the properties of an object using dot notation `.`.

Here's an example of accessing object properties using dot notation:

```js title="app.js"
// Accessing object properties using dot notation
let person = {
name: 'John Doe',
age: 30,
email: '[email protected]'
};

console.log(person.name); // John Doe
console.log(person.age); // 30
console.log(person.email); // [email protected]

// Accessing object properties using dot notation
person.name = 'Ajay Dhangar';
console.log(person.name); // Ajay Dhangar
```

In the above example, we have accessed the properties of the object `person` using dot notation.

### Bracket Notation

You can also access the properties of an object using bracket notation `[]`.

Here's an example of accessing object properties using bracket notation:

```js title="app.js"
// Accessing object properties using bracket notation
let person = {
name: 'John Doe',
age: 30,
email: '[email protected]'

};

console.log(person['name']); // John Doe
console.log(person['age']); // 30
console.log(person['email']); // [email protected]
```

In the above example, we have accessed the properties of the object `person` using bracket notation.

## Object Destructuring

Object destructuring is a way to extract properties from an object and assign them to variables.

Here's an example of object destructuring:

```js title="app.js"
// Object destructuring

let person = {
name: 'John Doe',
age: 30,
email: '[email protected]'
};

let { name, age, email } = person;

console.log(name); // John Doe
console.log(age); // 30
console.log(email); // [email protected]
```

In the above example, we have extracted the properties `name`, `age`, and `email` from the object `person` and assigned them to variables using object destructuring.

## Object Methods

An object can also have methods. A method is a function that is a property of an object.

Here's an example of object methods:

```js title="app.js"
// Object methods

let person = {
name: 'John Doe',
age: 30,
email: '[email protected]',
greet: function() {
return `Hello, my name is ${this.name}`;
}
};

console.log(person.greet()); // Hello, my name is John Doe
```

In the above example, we have added a method `greet` to the object `person`.

## Object Prototypes

In JavaScript, every object has a prototype. The prototype is also an object. All JavaScript objects inherit their properties and methods from their prototype.

Here's an example of object prototypes:

```js title="app.js"
// Object prototypes

let person = {
name: 'John Doe',
age: 30,
email: '[email protected]',
greet: function() {
return `Hello, my name is ${this.name}`;
}

};

console.log(person.toString()); // [object Object]
```

In the above example, we have called the `toString` method on the object `person`. The `toString` method is inherited from the prototype of the object `person`.

:::info Note

In JavaScript, all objects inherit from `Object.prototype`. The `Object.prototype` is the prototype of all objects.

:::

## Conclusion

In this tutorial, we learned about objects in JavaScript. We learned how to create objects, access object properties, and methods. We also learned about object destructuring, object methods, and object prototypes.
31 changes: 31 additions & 0 deletions docs/javascript/operators/bitwise-operators-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ classDiagram

The following are the types of bitwise operators in JavaScript:

| Operand 1 | Operand 2 | `&` (AND) | `\|` (OR) | `^` (XOR) | `~ `(NOT) | `<<` (Left Shift) | `>>` (Right Shift) |
|-----------|-----------|---------|-------|---------|---------|-----------------|------------------|
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
| 1 | 2 | 0 | 3 | 3 | 1 | 2 | 0 |
| 2 | 3 | 2 | 3 | 1 | 1 | 4 | 1 |
| 3 | 4 | 0 | 7 | 7 | 1 | 6 | 1 |
| 4 | 5 | 4 | 5 | 1 | 1 | 8 | 2 |
| 5 | 6 | 4 | 7 | 3 | 1 | 10 | 2 |
| 6 | 7 | 6 | 7 | 1 | 1 | 12 | 3 |
| 7 | 8 | 0 | 15 | 15 | 1 | 14 | 3 |
| 8 | 9 | 8 | 9 | 1 | 1 | 16 | 4 |
| 9 | 10 | 8 | 11 | 3 | 1 | 18 | 4 |
| 10 | 11 | 10 | 11 | 1 | 1 | 20 | 5 |
| 11 | 12 | 10 | 15 | 7 | 1 | 24 | 5 |
| 12 | 13 | 12 | 13 | 1 | 1 | 26 | 6 |
| 13 | 14 | 12 | 15 | 3 | 1 | 28 | 6 |
| 14 | 15 | 14 | 15 | 1 | 1 | 30 | 7 |
| 15 | 16 | 0 | 31 | 31 | 1 | 30 | 7 |
| 16 | 17 | 16 | 17 | 1 | 1 | 32 | 8 |
| 17 | 18 | 16 | 19 | 3 | 1 | 36 | 8 |
| 18 | 19 | 18 | 19 | 1 | 1 | 40 | 9 |
| 19 | 20 | 16 | 23 | 3 | 1 | 44 | 9 |
| 20 | 21 | 16 | 21 | 5 | 1 | 48 | 10 |
| 21 | 22 | 20 | 23 | 3 | 1 | 52 | 10 |
| 22 | 23 | 22 | 23 | 1 | 1 | 56 | 11 |
| 23 | 24 | 16 | 31 | 7 | 1 | 56 | 11 |
| 24 | 25 | 24 | 25 | 1 | 1 | 48 | 12 |
| 25 | 26 | 24 | 27 | 3 | 1 | 52 | 12 |


## Bitwise AND Operator (`&`)

The bitwise AND operator (`&`) is used to perform a bitwise AND operation on two integers.
Expand Down
2 changes: 1 addition & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const config = {
navbar: {
title: "CodeHarborHub",
logo: {
alt: "My Site Logo",
alt: "CodeHarborHub Logo",
src: "img/nav-logo.jpg",
},
items: [
Expand Down
Loading
Loading