From be8a0f0ebcbfdb0865d9b4b70ab6b69a58c333da Mon Sep 17 00:00:00 2001 From: Michael Azeez-Adekanmbi <137731808+Mykel-Az@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:56:57 +0100 Subject: [PATCH 1/3] Update Contributors.md --- Contributors.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Contributors.md b/Contributors.md index a9e9ede..5f49a74 100644 --- a/Contributors.md +++ b/Contributors.md @@ -5,4 +5,5 @@ 1. icodejsx 2. ogbon(Segun Amosu) 3. Solomon Eseme +4. Mykel-Az From dce04e52f2afcd2f20ac64529b63a25446e2c074 Mon Sep 17 00:00:00 2001 From: Michael Azeez-Adekanmbi <137731808+Mykel-Az@users.noreply.github.com> Date: Mon, 20 Nov 2023 18:04:08 +0100 Subject: [PATCH 2/3] Update Lexical Scope.md --- Lexical Scope.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/Lexical Scope.md b/Lexical Scope.md index b73a209..fd3fe54 100644 --- a/Lexical Scope.md +++ b/Lexical Scope.md @@ -1 +1,81 @@ -# Lexical Scope +# Lexical Scope in JavaScript + +Lexical scope is a fundamental concept in JavaScript that governs the visibility and accessibility of variables within the code. It describes how the JavaScript engine resolves variable names during the runtime of a program. + +## Table of Contents +- [Scope](#scope) +- [Lexical Scope](#lexical-scope) +- [Example](#example) +- [Closure](#closure) +- [Conclusion](#conclusion) + +## Scope + +Scope refers to the context in which variables are declared and accessed. In JavaScript, there are two types of scope: global scope and local scope. + +- **Global Scope:** Variables declared outside of any function or block have global scope, meaning they can be accessed from any part of the code. + +- **Local Scope:** Variables declared inside a function or block have local scope, and they are only accessible within that function or block. + +## Lexical Scope + +Lexical scope, also known as static scope, is determined at the time of code writing. It is based on the physical placement of variables and blocks in the code. In other words, the scope of a variable is determined by its location within the source code. + +```javascript +function outer() { + let outerVar = 'I am in the outer function'; + + function inner() { + let innerVar = 'I am in the inner function'; + console.log(outerVar); // Accessing outerVar from the outer function + } + + inner(); +} + +outer(); +``` + +## Example +```JavaScript +function example() { + let x = 10; + + if (true) { + let y = 20; + console.log(x); // Accessing x from the outer scope + console.log(y); // Accessing y from the local scope + } + + console.log(x); // Accessing x from the outer scope + // console.log(y); // This would result in an error, as y is not defined in this scope +} + +example(); +``` + +In this example, the x variable is accessible both inside and outside the if block because it's declared in the outer scope. However, the y variable is only accessible within the if block due to its local scope. + +## Closure + +Closures are a natural outcome of lexical scope in JavaScript. A closure occurs when a function is defined within another function, and the inner function retains access to the outer function's variables even after the outer function has finished executing. + +```JavaScript +function outer() { + let outerVar = 'I am from outer'; + + function inner() { + console.log(outerVar); // Accessing outerVar from the closure + } + + return inner; +} + +const closureFunction = outer(); +closureFunction(); // Logs 'I am from outer' + +``` +In this example, the inner function forms a closure over the outerVar, allowing it to access outerVar even after the outer function has completed execution. + +## Conclusion +Understanding lexical scope is crucial for writing maintainable and error-free JavaScript code. It dictates how variables are accessed and provides the foundation for concepts like closures. By grasping lexical scope, developers can write more predictable and organized code. From 7a799e475f92ca4eaeed1ee1f02ab55fb94b0f85 Mon Sep 17 00:00:00 2001 From: Mykel-Az Date: Tue, 21 Nov 2023 00:29:45 +0100 Subject: [PATCH 3/3] new commit --- MBClass2.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 MBClass2.md diff --git a/MBClass2.md b/MBClass2.md new file mode 100644 index 0000000..9a38d23 --- /dev/null +++ b/MBClass2.md @@ -0,0 +1,20 @@ +# GitHub Overview + +GitHub is a web-based hosting service for version control using Git, primarily utilized for managing software code. It encompasses the full functionality of distributed version control and source code management offered by Git while introducing its unique features. + +## Difference between Git Merging and Git Rebasing + +- **Git Merging**: Combines changes from one branch (source) into another (target) by creating a new merge commit that integrates changes from both branches. +- **Git Rebasing**: Involves creating a new set of commits applied atop the target branch, essentially moving the changes from one branch onto another. + +## Git Commands and Their Uses + +- `git init`: Initializes Git within a local repository in the terminal. +- `git branch -m {name}`: Displays the current branch. +- `git checkout -b {name}`: Creates a new branch and switches to it. +- `git add .`: Adds files to the staging area. +- `git status`: Checks the status of files in the staging area. +- `git commit -m {message}`: Moves files to the HEAD before sending them to the remote repository. +- `git push origin {name}`: Sends files to the remote repository on GitHub. +- `git pull origin {name}`: Retrieves files from the remote repository. +