Skip to content
Open
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
8 changes: 4 additions & 4 deletions Contributors.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Contributors List
# Contributors List

*Names*
_Names_

1. icodejsx
1. icodejsx
2. ogbon(Segun Amosu)
3. Solomon Eseme

4. Oye Olaleye
3 changes: 3 additions & 0 deletions ass1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Git Merge: The `git merge` command combines the changes from one branch into another branch, creating a new commit with both branch's changes. It Integrates changes from one branch into another, creating a new merge commit and maintaining the original branch structure. It's good for preserving history and is suitable for shared branches.
- Git Rebase: The `git rebase` command rewrites the commit history by moving the starting point of the current branch to the tip of another branch. It Rewrites commit history by applying the commits on top of another branch, resulting in a linear history. It's great for a cleaner history but might cause issues in shared branches due to history rewriting.

The choice between them depends on whether you prioritise a clean, linear history (rebase) or preserving the original branch structure (merge), considering the impact on shared branches and collaboration.
53 changes: 53 additions & 0 deletions ass2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Lexical Structure

Lexical scope, also known as static scope, is a fundamental concept in JavaScript (and many other programming languages) that determines how variable names are resolved in a program. Lexical scope is based on the physical structure of the code and where variables and functions are declared within the code.
In JavaScript, when a variable is referenced, the JavaScript engine looks for that variable in the current scope and, if not found, it traverses the scope chain to find it. Lexical scope follows these rules:

- Scope Nesting: Each function or block of code defines a new scope. Variables declared inside a scope are accessible within that scope and any nested scopes.
- Outer Scope Access: A scope has access to variables in its containing (outer) scope. This is often referred to as the "closure" property, allowing inner functions to access variables from their containing functions.
- Compile-Time Determination: Lexical scope is determined at compile-time or during code parsing, based on where variables and functions are declared in the code. This means that scope is static and doesn't change during runtime.

Code snippet 1
function outer() {
var outerVar = "I'm in the outer scope";

function inner() {
var innerVar = "I'm in the inner scope";
console.log(outerVar); // Inner function can access the outerVar

}

inner();
console.log(innerVar); // This will result in an error because innerVar is not accessible here.
}

outer();

Code snippet 2
function outerfunction( ){
let count = 0;
return function ( ){
count++;
console.log(count)
}
}

const counterOne = outerfunction()
const counterTwo = outerfunction()

counterOne() //1
counterOne() //2
counterTwo() //1
counterOne() //3
counterTwo() //2
counterOne() //4

Here's what's happening step by step:

- outerfunction is called twice, creating two separate closures.
- outerfunction initializes count as 0 and returns an inner function that, when called, increments count and logs its value.
- counterOne and counterTwo are two separate instances of the inner function returned by outerfunction, and each maintains its own lexical scope (its own count variable).
When you execute counterOne() and counterTwo(), they operate independently:
- counterOne():
- Initializes its own count variable (in its closure) and increments it with each call. Thus, it logs the count starting from 1 and increments accordingly.
- counterTwo(): \* Operates separately and initializes its own count, starting from 1.
Hence, you're seeing the count increase for each function separately, as they have their own independent closures keeping track of their respective counts.
45 changes: 45 additions & 0 deletions ass3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Events in backend

Event listening in backend typically involves listening to events or requests from clients, such as HTTP requests in web servers. Below is an example using Node.js and Express, a popular web framework for Node.js, to set up an HTTP server that listens for incoming requests:
First, ensure you have Node.js installed and create a new directory for your project. Then, initialize a new Node.js project by running npm init in the terminal to create a package.json file.
Next, install the Express framework by running npm install express.
Here's a basic code snippet to create an HTTP server that listens for GET requests using Express:

const express = require('express');
const app = express();
const port = 3000; // Choose a port number

// Route handler for GET request to the root URL
app.get('/', (req, res) => {
res.send('Hello, this is the backend server!');
});

// Start the server to listen on the specified port
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});

- app.get('/', ...) sets up a route handler for GET requests to the root URL ('/'). When a GET request is made to the root URL, it sends the response 'Hello, this is the backend server!'.
- app.listen(port, ...) starts the server and makes it listen on the specified port (in this case, port 3000).

Ways to create a listener in the frontend to listen to the backend

So, what you're looking for is the ability to send or "push" data from server to client.

The typical way of doing this is with a webSocket or socket.io connection. The client connects to the server and creates a lasting connection to the server. From then on, the server can just send data to the client over that connection whenever it wants to. The client then creates a listener on that connection so it will know when there is incoming data and it can then act accordingly based on the data.
webSocket is the standard built-into browsers that enables this type of function. socket.io is an additional client and server layer built on top of a webSocket connection that adds a lot of useful features such as auto-reconnection if the connection dies, a JSON message definition layer so you don't have to define your own data format, etc...
Here's how this would normally work:

1. When the server initializes, it creates a socket.io listener for incoming socket.io connections. webSocket/socket.io are built to "share" the same web server that you are using for loading web pages so you don't need an additional server or port.
2. When a page loads in the browser, some Javascript in that page creates a socket.io connection to the server.
3. The client then sets up listeners for whatever messages it wants to be able to act on.
4. Meanwhile, when the server gets something that it wants to send to the clients, it can either send that data to all currently connected clients or it can send it to only one specific client.
5. Then, the client's event listener will trigger and it will receive the data.
6. The client can then decide what it wants to do with the data, typically insert something in the current displayed page.
7. When the browser is changed to another web page, the socket.io connection will automatically be disconnected.

Key Differences:

- WebSocket is a communication protocol that provides full-duplex communication channels over a single connection, while Socket.IO is a library that facilitates real-time, event-based communication and is built on top of WebSocket.
- Socket.IO offers more than just WebSocket. It provides fallback mechanisms and additional features to ensure real-time communication, while WebSocket is a lower-level protocol focused on providing a full-duplex communication channel.
- WebSocket is a standardized protocol, while Socket.IO is a library providing additional functionalities and addressing browser compatibility issues related to WebSocket.
43 changes: 43 additions & 0 deletions ass4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
Map:

Purpose: The map function is used to transform each element of an array based on a provided function.

const numbers = [1, 2, 3, 4, 5];
const squaredNumbers = numbers.map((num) => num \* num);
// squaredNumbers is now [1, 4, 9, 16, 25]

Filter:

Purpose: The filter function is used to create a new array containing only the elements that pass a certain condition.

const numbers = [1, 2, 3, 4, 5];
const evenNumbers = numbers.filter((num) => num % 2 === 0);
// evenNumbers is now [2, 4]

Loop:

Purpose: A loop is a programming construct that allows you to repeatedly execute a block of code until a certain condition is met.

const numbers = [1, 2, 3, 4, 5];
for (let i = 0; i < numbers.length; i++) {
console.log(numbers[i]);
}
// This will print each number in the array

const people = [
{ name: 'Alice', age: 25 },
{ name: 'Bob', age: 30 },
{ name: 'Charlie', age: 22 },
{ name: 'David', age: 35 },
];

// Use map to create a new array with a message for each person
const greetings = people.map((person) => `Hello, ${person.name}!`);

// Use filter to get only people who are 30 or older
const olderPeople = people.filter((person) => person.age >= 30);

// Use a loop to print the greetings and ages of older people
for (let i = 0; i < olderPeople.length; i++) {
console.log(`${greetings[i]} Age: ${olderPeople[i].age}`);
}