Skip to content

Commit

Permalink
Switched to Docusaurus
Browse files Browse the repository at this point in the history
  • Loading branch information
Neonsy authored and DrNeonsy committed Jun 4, 2024
1 parent b3480f3 commit 6149402
Show file tree
Hide file tree
Showing 52 changed files with 9,997 additions and 3,480 deletions.
48 changes: 29 additions & 19 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
name: Deploy to GitHub Pages

on:
# Trigger the workflow every time you push to the `main` branch
# Using a different branch name? Replace `main` with your branch’s name
push:
branches: [main]
# Allows you to run this workflow manually from the Actions tab on GitHub.
workflow_dispatch:

# Allow this job to clone the repo and create a page deployment
permissions:
contents: read
pages: write
id-token: write
branches:
- main

jobs:
build:
name: Build Docusaurus
runs-on: ubuntu-latest
steps:
- name: Checkout your repository using git
uses: actions/[email protected]
- name: Install, build, and upload your site
uses: withastro/[email protected]
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v2
with:
version: 7 # Specify the pnpm version

- name: Install dependencies
run: pnpm install
working-directory: ./Docs # Specify the working directory

- name: Build website
run: pnpm run build
working-directory: ./Docs # Specify the working directory

- name: Upload Build Artifact
uses: actions/upload-pages-artifact@v3
with:
package-manager: pnpm@latest # The Node package manager that should be used to install dependencies and build your site. Automatically detected based on your lockfile. (optional)
node-version: '22' # The specific version of Node that should be used to build your site. Defaults to 20. (optional)
path: ./Docs # The root location of your Astro project inside the repository. (optional)
path: ./Docs/build # Specify the path to the build directory

deploy:
name: Deploy to GitHub Pages
needs: build
runs-on: ubuntu-latest

permissions:
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
Expand Down
35 changes: 15 additions & 20 deletions Docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# build output
dist/
# generated types
.astro/
# Dependencies
/node_modules

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Production
/build

# Generated files
.docusaurus
.cache-loader

# environment variables
.env
.env.production

# macOS-specific files
# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# custom
.vscode/
.idea/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
48 changes: 0 additions & 48 deletions Docs/README.md

This file was deleted.

80 changes: 0 additions & 80 deletions Docs/astro.config.mjs

This file was deleted.

3 changes: 3 additions & 0 deletions Docs/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
---
title: Const VS Let
description: In this article, we will learn about the difference between const and let in JavaScript.
tableOfContents:
maxHeadingLevel: 4
prev: false
next: false
description: My thoughts on the differences between `const` and `let` in JavaScript.
authors: neonsy
tags: [javascript, debated]
toc_max_heading_level: 4
slug: JavaScript/Const VS Let
---

import Image from '@theme/IdealImage';

<Image img={require('./const vs let.png')} />

As you may have already heard, JavaScript has two types of variables, `let` and `const`.
You'd probably excpect that `const` stands for making a variable `constant`, or rather the value? Well, you can already see the problem.

Before we dive into the topic, let's first understand what a `constant` variable is meant to do.
When you make _something_ `constant`, you can't change the that due to immutability.

:::note
{/* truncate */}

:::info
When something is `immutable`, it means that it can't be changed.
However, what you actually make `immutable` differs from language to language.

Expand All @@ -25,8 +31,8 @@ Not everything that is `constant`, is neccessarily / automatically `immutable`,
In C#, the `const` keyword is used to define `constant` values that are known at compile time and cannot be changed. However, `const` can only be applied to primitive types and strings, not to objects.

If you want to create an immutable object, you should use the readonly keyword instead.
The readonly keyword can be used with fields, and it ensures that the field can only be assigned a value once, either at the time of declaration or in the constructor of the class.
However, if the field is a reference type (<span class="text-orange-600 dark:text-orange-400">like an object</span>), you can still modify the attributes of the object it points to.
The readonly keyword can be used with fields, and it ensures that the field can only be assigned a value once, either at the time of declaration or in the constructor of the className.
However, if the field is a reference type (<span className="text-orange-600 dark:text-orange-400">like an object</span>), you can still modify the attributes of the object it points to.

## Looking at Java

Expand All @@ -40,7 +46,7 @@ However, the properties of objects or elements of arrays can still be modified.

Why? To understand that, let's look at pointers in C++.

:::note
:::info
Python does not even bother having a `const` keyword, which is kinda funny. When writing Python, you have to rely on naming conventions, to mark something as a `constant`.
:::

Expand All @@ -64,7 +70,7 @@ int* const ptr = &num;
As you can see, we have a variable `num` that has the value `10`.
Then, we have a pointer `ptr` that points to the variable `num`.
That pointer is `constant`, so we <span class="text-orange-600 dark:text-orange-400">can't change the value of **the pointer**.</span>
That pointer is `constant`, so we <span className="text-orange-600 dark:text-orange-400">can't change the value of **the pointer**.</span>

How would you change the value of the variable that the pointer points to?
Well, by just changing the value of the variable that the pointer points to, using the `*` syntax.
Expand Down Expand Up @@ -96,17 +102,17 @@ The conclusion is that while `const` and `let` in JavaScript have specific behav

### Looking at objects in JavaScript

Everything that is <span class="text-orange-600 dark:text-orange-400">not</span> a primitive type is an object in JavaScript.
Everything that is <span className="text-orange-600 dark:text-orange-400">not</span> a primitive type is an object in JavaScript.
That includes arrays, functions, maps etc.

So while the pointer example above points at the differences between `let` and `const`, there's still something we need to address.

#### What is an object?

A primitive type (<span class="text-orange-600 dark:text-orange-400">like an integer or a boolean</span>) stores its value directly in the memory allocated for the variable.
A primitive type (<span className="text-orange-600 dark:text-orange-400">like an integer or a boolean</span>) stores its value directly in the memory allocated for the variable.
For example, if you have an integer variable with a value of 5, the memory location for that variable will directly contain the number 5.

An object however, stores a reference (<span class="text-orange-600 dark:text-orange-400">or pointer</span>) to the memory location where the actual data is stored.
An object however, stores a reference (<span className="text-orange-600 dark:text-orange-400">or pointer</span>) to the memory location where the actual data is stored.
So, when you create an object, the variable holds the address of where the object's data is located, not the data itself.
This means that if you have two variables referring to the same object, changes made through one variable will be reflected when accessing the object through the other variable.

Expand All @@ -116,7 +122,7 @@ When you use `const` in JavaScript, you are declaring that the variable cannot b
However, the properties of the object can still be changed, because you are holding a reference to the object, not the object itself.

This in return means, that if you have a `const` variable for an integer, you cannot change the value of the variable, because the variable holds the value and not a reference.
:::note
:::info
This is a slight guess on my end, because it still depends on how the language handles these types in the end.
Therefore, I'm basing my explaination on the mixture of what I know about the language and what I've learned about memory.
:::
Expand All @@ -140,7 +146,7 @@ When reading through all of this, you might be wondering: How can we make sure t
Well, JavaScript got you covered with the `object.freeze()` method.
This method will freeze the object and prevent any changes to the object's attributes.

:::note
:::info
If you really want to freeze an object, keep in mind that based on the object's size and dependencies, this might get expansive.
:::

Expand All @@ -150,8 +156,8 @@ JavaScript has two types of variable declarations: `const` and `let`, where `con

In languages like C# and Java, `const` and `final` keywords create compile-time constants, but JavaScript's `const` allows object properties to be modified.

:::note
You could of course `const` attributes of a class, but that would probably defeat the purpose of using a class.
:::info
You could of course `const` attributes of a className, but that would probably defeat the purpose of using a className.
:::

Objects in JavaScript store references to memory locations, so using `const` means the reference can't change, but the object's properties still can.
Expand Down
5 changes: 5 additions & 0 deletions Docs/blog/authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
neonsy:
name: Neonsy
title: Owner and Maintainer
url: https://github.com/Neonsy/
image_url: https://avatars.githubusercontent.com/u/118444485?v=4
24 changes: 24 additions & 0 deletions Docs/blog/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
javascript:
label: JavaScript
permalink: /javascript
description: JavaScript related topics

typescript:
label: TypeScript
permalink: /typescript
description: TypeScript related topics

nodejs:
label: Node.js
permalink: /nodejs
description: Node.js related topics

news:
label: News
permalink: /news
description: News related information

debated:
label: Debated
permalink: /debated
description: Hot debated topics
Loading

0 comments on commit 6149402

Please sign in to comment.