The Journey of #100DaysOfCode (@Ayman_Dandan)

Hello community!

Iโ€™ve been challenged to start the #100DayCodeChallenge, and guess what?! Challenge Accepted!! :grin: So, for the next 100 days, Iโ€™ll be sharing my knowledge, learning, and experiences.

Below is my progress from previous days, and Iโ€™ll now be updating regularly from today. If youโ€™re up for it, join me on this adventure! :sparkles:

7e886ab87e66a70d1ba74283be9d2ce98a0fdabe_2_690x388

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ: Introducing ๐๐ฅ๐จ๐›๐ฌ

no, not the slimesโ€ฆ although quite similar in not having a defined form or structure

A Blob (short for Binary Large Object) is an object that represents immutable raw binary data and can take many forms. Itโ€™s commonly used to handle File uploading, Image processing, and large data operations. Blobs can be read as text or binary data or converted into a ReadableStream for further processing.

โ†’ ๐˜ฝ๐™ก๐™ค๐™— ๐™˜๐™ง๐™š๐™–๐™ฉ๐™ž๐™ค๐™ฃ:
Blobs are created using the Blob() constructor, which takes an array of parts (data that is stored in the blob), and mainly the type of the blobโ€™s data. For example, text/plain, image/jpeg, application/json, audio/mp3, โ€ฆ

โ†’ ๐˜พ๐™ง๐™š๐™–๐™ฉ๐™ž๐™ฃ๐™œ ๐˜ฝ๐™ก๐™ค๐™— ๐™๐™๐™‡:
Blob URLs allow you to reference Blob objects in your applications as if they were regular URLs. This is particularly useful for creating downloadable links or embedding multimedia content.

โ†’ ๐™๐™š๐™ซ๐™ค๐™ ๐™ž๐™ฃ๐™œ ๐˜ฝ๐™ก๐™ค๐™— ๐™๐™๐™‡:
Of course, after you are done with the URL, you need to free up the memory used by the blob URL by revoking it. :broom:

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ : ๐๐ซ๐จ๐ฆ๐ข๐ฌ๐ž๐ฌ ๐ข๐ง ๐‰๐’
A Promise in JavaScript is a way to handle asynchronous operations like downloading a file and sending/receiving a package from the backend. They make the user able to continue in the page and/or doing something else without waiting for the operation to finish. Promises also are used for better error handling, better flow of control definition in asynchronous logic, and improving Code readability.

And always resolve your promises, donโ€™t keep them pending :smile: :computer:

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ‘ of 100DaysOfCode

  • ๐˜พ๐™–๐™ก๐™ก๐˜ฝ๐™–๐™˜๐™ ๐™จ -

A callback is a function that is passed to another function as an argument and is intended to be executed after some event or task has been completed. They can be used to refactor code even more by refactoring functions, a simple example of this would be a simple calculate function that takes two variables and an operator.

Callbacks are also used to handle asynchronous operations, such as fetching data from a server, reading files, or waiting for user input.

  • ๐๐ž๐ฐ๐š๐ซ๐ž ๐จ๐Ÿ ๐ญ๐ก๐ž โ€œ๐˜พ๐™–๐™ก๐™ก๐™—๐™–๐™˜๐™  ๐™ƒ๐™š๐™ก๐™กโ€
    When dealing with multiple asynchronous operations that depend on each other, you might encounter โ€œcallback hell,โ€ where callbacks are nested within other callbacks, making the code difficult to read and maintain.

And so, to avoid callback hell, one can use ๐ฉ๐ซ๐จ๐ฆ๐ข๐ฌ๐ž๐ฌ using then/catch blocks, or using ๐š๐ฌ๐ฒ๐ง๐œ/๐š๐ฐ๐š๐ข๐ญ.

For more clarification, please refer to the attached code.

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ’ of 100DaysOfCode

  • ๐™๐™š๐™จ๐™ฉ ๐™‹๐™–๐™ง๐™–๐™ข๐™š๐™ฉ๐™š๐™ง๐™จ -

Before knowing what rest parameters are, I would like to talk first about the โ€˜argumentsโ€™ object in JS.

The โ€˜argumentsโ€™ object is an ๐˜ข๐˜ณ๐˜ณ๐˜ข๐˜บ-๐˜ญ๐˜ช๐˜ฌ๐˜ฆ object that is found as a local variable within all ๐˜ฏ๐˜ฐ๐˜ฏ-๐˜ข๐˜ณ๐˜ณ๐˜ฐ๐˜ธ functions. You can refer to a functionโ€™s arguments inside that function by using its โ€˜argumentsโ€™ object.
I said it is an array-like object; since, like arrays, they have entries for each argument the function was called with, with the first entryโ€™s index at 0(ex. arguments[0]), and the function length is also included within. However, they donโ€™t have other array functions like forEach and map functions.

The โ€˜argumentsโ€™ object can access any argument of a function even when not specified in the declaration of the said function, which means that the function would have access for infinite arguments.

Now back to rest parameters :sweat_smile:
much like โ€˜argumentsโ€™, they allow the function to have access to indefinite number of arguments as an ๐’‚๐’“๐’“๐’‚๐’š.

A function definitionโ€™s last parameter can be prefixed with " โ€ฆ " which will cause all remaining (user supplied) parameters to be placed within an Array object.

Rest Parameters are not limited to only the length function, they can perform what any array can do like using slice, forEach, map, sort, etcโ€ฆ
As they are used as the last parameter, it leaves space for other parameters to be specified.

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ“ of 100DaysOfCode

  • ๐˜ฟ๐™š๐™›๐™–๐™ช๐™ก๐™ฉ ๐™‹๐™–๐™ง๐™–๐™ข๐™š๐™ฉ๐™š๐™ง๐™จ -

Default parameters in JavaScript allow you to initialize a function with default values if no arguments are provided or if โ€˜๐˜ถ๐˜ฏ๐˜ฅ๐˜ฆ๐˜ง๐˜ช๐˜ฏ๐˜ฆ๐˜ฅโ€™ is passed as an argument. This feature helps make your functions more robust and reduces the need for additional code to handle cases where arguments are not provided.

Default parameters can be used:
โ†’ to simplify function calls by eliminating the need to pass values explicitly for all parameters.
โ†’ to avoid โ€˜undefinedโ€™ values.
โ†’ to improve code readability.
โ†’ with destructuring to provide default values for arrays and/or object properties.
->with expressions, including calls to other functions, allowing for complex default values.

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ” of 100DaysOfCode

  • ๐™ก๐™ค๐™˜๐™–๐™ก๐™Ž๐™ฉ๐™ค๐™ง๐™–๐™œ๐™š -

๐—น๐—ผ๐—ฐ๐—ฎ๐—น๐—ฆ๐˜๐—ผ๐—ฟ๐—ฎ๐—ด๐—ฒ in JavaScript is a type of web storage that allows websites to store data persistently in a userโ€™s browser. Unlike ๐˜ด๐˜ฆ๐˜ด๐˜ด๐˜ช๐˜ฐ๐˜ฏ๐˜š๐˜ต๐˜ฐ๐˜ณ๐˜ข๐˜จ๐˜ฆ, which stores data for a single session (until the browser tab is closed), ๐˜ญ๐˜ฐ๐˜ค๐˜ข๐˜ญ๐˜š๐˜ต๐˜ฐ๐˜ณ๐˜ข๐˜จ๐˜ฆ retains data even after the browser is closed and reopened.

Why would one use ๐˜ญ๐˜ฐ๐˜ค๐˜ข๐˜ญ๐˜š๐˜ต๐˜ฐ๐˜ณ๐˜ข๐˜จ๐˜ฆ?
โ†’ Data remains available across browser sessions, so users can return to your site later and still have their data.
โ†’ Reduces the need for repeated server requests, improving load times and reducing server load.
โ†’ Simple API for storing, retrieving, and removing data.
โ†’ Typically allows for 5-10MB of storage per origin, which is more than cookies.

However, one should not store any valuable / important information since the data stored in ๐˜ญ๐˜ฐ๐˜ค๐˜ข๐˜ญ๐˜š๐˜ต๐˜ฐ๐˜ณ๐˜ข๐˜จ๐˜ฆ is accessible through JavaScript, so it can be susceptible to cross-site scripting (XSS) attacks.
1721065433564

4 Likes

๐ƒ๐š๐ฒ ๐Ÿ• of 100DaysOfCode

  • ๐˜ผ๐™˜๐™˜๐™š๐™จ๐™จ๐™ž๐™ฃ๐™œ ๐™Š๐™—๐™Ÿ๐™š๐™˜๐™ฉ ๐™‹๐™ง๐™ค๐™ฅ๐™š๐™ง๐™ฉ๐™ž๐™š๐™จ -

Coming from a C background perspective, I thought that, in JavaScript, object properties would be very much like the structures in C and can only be accessed by using the dot notation, while bracket notation is used for array properties.

Little did I know, that was only one way in JS. Objects in JS are collections of key-value pairs, and there are several ways to access the values stored within these objects.

โ†’ ๐——๐—ผ๐˜ ๐—ก๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป:

  • Syntax: ๐˜ฐ๐˜ฃ๐˜ซ๐˜ฆ๐˜ค๐˜ต.๐˜ฑ๐˜ณ๐˜ฐ๐˜ฑ๐˜ฆ๐˜ณ๐˜ต๐˜บ

โ†’ ๐—•๐—ฟ๐—ฎ๐—ฐ๐—ธ๐—ฒ๐˜ ๐—ก๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป:

  • Syntax: ๐˜ฐ๐˜ฃ๐˜ซ๐˜ฆ๐˜ค๐˜ต['๐˜ฑ๐˜ณ๐˜ฐ๐˜ฑ๐˜ฆ๐˜ณ๐˜ต๐˜บ']
    This method is useful when the property name is dynamic or not a valid identifier (e.g., contains spaces or starts with a number).

โ†’ ๐—จ๐˜€๐—ถ๐—ป๐—ด ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ๐˜€ ๐˜„๐—ถ๐˜๐—ต ๐—•๐—ฟ๐—ฎ๐—ฐ๐—ธ๐—ฒ๐˜ ๐—ก๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป:
Same as Bracket Notation, but the property name is stored in a variable, allowing for a more flexible access of the properties.

โ†’ ๐——๐—ฒ๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐˜‚๐—ฟ๐—ถ๐—ป๐—ด๐—”๐—ฐ๐—ฐ๐—ฒ๐˜€๐˜€๐—ถ๐—ป๐—ด ๐—ก๐—ฒ๐˜€๐˜๐—ฒ๐—ฑ ๐—ข๐—ฏ๐—ท๐—ฒ๐—ฐ๐˜๐˜€:
Nested objects can be accessed by chaining dot or bracket notation, or mixing between them.

โ†’ ๐——๐—ฒ๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐˜‚๐—ฟ๐—ถ๐—ป๐—ด:
Destructuring assignment can be used to extract values from objects and store them in variables.

Each of these methods offers flexibility depending on the situation, such as the need for dynamic property access or dealing with nested structures.

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ– of 100DaysOfCode

  • ๐™„๐™ข๐™ข๐™ช๐™ฉ๐™–๐™—๐™ž๐™ก๐™ž๐™ฉ๐™ฎ & ๐˜ฟ๐™š๐™š๐™ฅ๐™๐™ง๐™š๐™š๐™ฏ๐™ž๐™ฃ๐™œ :snowflake: -

In JavaScript, objects are mutable by default. This means that their properties can be changed after they are created. However, there are times when we want to ensure that an object remains immutable โ€” preventing any modifications to it or its nested objects.

Why is ๐˜๐˜ฎ๐˜ฎ๐˜ถ๐˜ต๐˜ข๐˜ฃ๐˜ช๐˜ญ๐˜ช๐˜ต๐˜บ important?
โ†’ Immutable objects ensure that the state cannot be modified unexpectedly, making the code more predictable and easier to understand.
โ†’ With immutability, tracking changes and understanding state transitions becomes simpler, which aids in debugging and testing.
โ†’ It simplifies the implementation of undo and redo functionalities, like those in text editors, as previous states are easily retrievable.

Hereโ€™s a practical way to achieve immutability using a technique called ๐ƒ๐ž๐ž๐ฉ ๐…๐ซ๐ž๐ž๐ณ๐ข๐ง๐ .

๐˜‹๐˜ฆ๐˜ฆ๐˜ฑ ๐˜๐˜ณ๐˜ฆ๐˜ฆ๐˜ป๐˜ช๐˜ฏ๐˜จ is achieved by recursively calling the build-in method ๐˜–๐˜ฃ๐˜ซ๐˜ฆ๐˜ค๐˜ต.๐˜ง๐˜ณ๐˜ฆ๐˜ฆ๐˜ป๐˜ฆ() to ensure that all nested arrays and objects are frozen, and thus Immutable.

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ— of 100DaysOfCode

  • ๐™๐™ค๐™ง-๐™‡๐™ค๐™ค๐™ฅ๐™จ ๐™ž๐™ฃ ๐™…๐™Ž -

In JavaScript, other than the traditional for loop, there are several types of for loops each suited to different kinds of tasks.

โ†’ ๐“๐ซ๐š๐๐ข๐ญ๐ข๐จ๐ง๐š๐ฅ โ€˜๐Ÿ๐จ๐ซโ€™ ๐ฅ๐จ๐จ๐จ๐ฉ:
This loop consists of Initialization (let i = 0), Condition (i < 5) and Increment (i++).
The traditional โ€˜๐˜ง๐˜ฐ๐˜ณโ€™ loop is useful when you know in advance how many times you need to execute a statement or a block of statements.

โ†’ โ€˜๐Ÿ๐จ๐ซ-๐ข๐งโ€™ ๐‹๐จ๐จ๐ฉ:
This loop iterates over the enumerable properties of an object. Itโ€™s typically used for iterating over the properties of objects.
However, โ€˜๐˜ง๐˜ฐ๐˜ณ-๐˜ช๐˜ฏโ€™ should not be used to iterate over arrays where the order of elements is important because it iterates over all enumerable properties, not just the numeric indexes.

โ†’ โ€˜๐Ÿ๐จ๐ซ-๐จ๐Ÿโ€™ ๐‹๐จ๐จ๐ฉ:
The โ€˜๐˜ง๐˜ฐ๐˜ณ-๐˜ฐ๐˜งโ€™ loop iterates over iterable objects like arrays, strings, maps, sets, etc. Itโ€™s preferred for arrays and other iterable objects.
This loop allows you to directly access the values of the iterable.

โ†’ โ€˜๐Ÿ๐จ๐ซ๐„๐š๐œ๐กโ€™ ๐ฆ๐ž๐ญ๐ก๐จ๐:
Although not a loop itself, the โ€˜๐˜ง๐˜ฐ๐˜ณ๐˜Œ๐˜ข๐˜ค๐˜ฉโ€™ method is commonly used for iterating over arrays. Itโ€™s a higher-order function that executes a provided function once for each array element.
This method is convenient but does not support โ€˜๐˜ฃ๐˜ณ๐˜ฆ๐˜ข๐˜ฌโ€™ or โ€˜๐˜ค๐˜ฐ๐˜ฏ๐˜ต๐˜ช๐˜ฏ๐˜ถ๐˜ฆโ€™ statements.

๐‘ฐ๐’ ๐‘บ๐’–๐’Ž๐’Ž๐’‚๐’“๐’š:
โ†’ Use a traditional ๐Ÿ๐จ๐ซ loop for simple numeric iterations.
โ†’ Use ๐Ÿ๐จ๐ซ-๐ข๐ง for iterating over object properties.
โ†’ Use ๐Ÿ๐จ๐ซ-๐จ๐Ÿ for iterating over iterable objects like arrays.
โ†’ Use ๐Ÿ๐จ๐ซ๐„๐š๐œ๐ก for array iterations when you donโ€™t need to break out of the loop early.

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐ŸŽ of 100DaysOfCode

  • ๐˜ผ๐™ง๐™ง๐™–๐™ฎ ๐™ˆ๐™š๐™ฉ๐™๐™ค๐™™๐™จ -

Array methods in JavaScript are built-in functions that you can use to perform common tasks on arrays, such as adding, removing, or manipulating elements.

โ†’ ๐—ฝ๐˜‚๐˜€๐—ต: Adds one or more elements to the end of an array.

โ†’ ๐—ฝ๐—ผ๐—ฝ: Removes the last element from an array.

โ†’ ๐˜€๐—ต๐—ถ๐—ณ๐˜: Removes the first element from an array.

โ†’ ๐˜‚๐—ป๐˜€๐—ต๐—ถ๐—ณ๐˜: Adds one or more elements to the beginning of an array.

โ†’ ๐˜€๐—น๐—ถ๐—ฐ๐—ฒ: Returns a shallow copy of a portion of an array into a new array object.

โ†’ ๐˜€๐—ฝ๐—น๐—ถ๐—ฐ๐—ฒ: Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.

โ†’ ๐—ฐ๐—ผ๐—ป๐—ฐ๐—ฎ๐˜: Merges two or more arrays.

โ†’ ๐—ณ๐—ผ๐—ฟ๐—˜๐—ฎ๐—ฐ๐—ต: Executes a provided function once for each array element.

โ†’ ๐—บ๐—ฎ๐—ฝ: Creates a new array with the results of calling a provided function on every element in the calling array.

โ†’ ๐—ณ๐—ถ๐—น๐˜๐—ฒ๐—ฟ: Creates a new array with all elements that pass the test implemented by the provided function.

โ†’ ๐—ฟ๐—ฒ๐—ฑ๐˜‚๐—ฐ๐—ฒ: Executes a reducer function (that you provide) on each element of the array, resulting in a single output value.

โ†’ ๐—ณ๐—ถ๐—ป๐—ฑ: Returns the value of the first element in the array that satisfies the provided testing function.

โ†’ ๐—ณ๐—ถ๐—ป๐—ฑ๐—œ๐—ป๐—ฑ๐—ฒ๐˜…: Returns the index of the first element in the array that satisfies the provided testing function.

โ†’ ๐—ถ๐—ป๐—ฐ๐—น๐˜‚๐—ฑ๐—ฒ๐˜€: Determines whether an array includes a certain value among its entries, returning true or false as appropriate.

โ†’ ๐˜€๐—ผ๐—ฟ๐˜: Sorts the elements of an array in place and returns the array.

โ†’ ๐—ฟ๐—ฒ๐˜ƒ๐—ฒ๐—ฟ๐˜€๐—ฒ: Reverses the order of the elements in an array in place.

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ of 100DaysOfCode

  • ๐™€๐™ญ๐™ฅ๐™ก๐™ค๐™ง๐™ž๐™ฃ๐™œ ๐™ˆ๐™ค๐™ฃ๐™œ๐™ค๐˜ฟ๐˜ฝ -

MongoDB is a NoSQL database that offers a flexible, scalable, and powerful way to store and manage data. Unlike traditional relational databases, MongoDB uses a document-oriented model, making it perfect for handling unstructured or semi-structured data.

๐—ช๐—ต๐—ฎ๐˜ ๐—ฎ๐—ฟ๐—ฒ ๐˜€๐—ผ๐—บ๐—ฒ ๐—ธ๐—ฒ๐˜† ๐—ณ๐—ฒ๐—ฎ๐˜๐˜‚๐—ฟ๐—ฒ๐˜€ ๐—ผ๐—ณ ๐— ๐—ผ๐—ป๐—ด๐—ผ๐——๐—•?

โ†’ ๐’๐œ๐ก๐ž๐ฆ๐š-๐ฅ๐ž๐ฌ๐ฌ: MongoDB stores data in flexible, JSON-like documents, meaning you donโ€™t need to define a schema upfront. This allows for easy data modeling and rapid iteration.

โ†’ ๐’๐œ๐š๐ฅ๐š๐›๐ข๐ฅ๐ข๐ญ๐ฒ: Designed with scalability in mind, MongoDB can handle large volumes of data and high traffic loads. It supports horizontal scaling through sharding, making it ideal for growing applications.

โ†’ ๐๐จ๐ฐ๐ž๐ซ๐Ÿ๐ฎ๐ฅ ๐๐ฎ๐ž๐ซ๐ฒ ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž: MongoDB offers a rich query language with support for ad-hoc queries, indexing, and real-time aggregation. You can easily retrieve and manipulate data using its expressive query syntax.

โ†’ ๐‡๐ข๐ ๐ก ๐๐ž๐ซ๐Ÿ๐จ๐ซ๐ฆ๐š๐ง๐œ๐ž: With features like in-memory storage engine, replication, and sharding, MongoDB delivers high performance for read and write operations, ensuring your application runs smoothly.

๐—ช๐—ต๐˜† ๐˜†๐—ผ๐˜‚ ๐˜€๐—ต๐—ผ๐˜‚๐—น๐—ฑ ๐˜‚๐˜€๐—ฒ ๐— ๐—ผ๐—ป๐—ด๐—ผ๐——๐—•:

โ†’ ๐…๐ฅ๐ž๐ฑ๐ข๐›๐ข๐ฅ๐ข๐ญ๐ฒ: The document model allows for storing complex data structures in a single record, making it easier to manage and evolve your data schema.

โ†’ ๐ƒ๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ๐ž๐ซ-๐…๐ซ๐ข๐ž๐ง๐๐ฅ๐ฒ: MongoDB integrates well with popular programming languages and frameworks, providing extensive documentation and a strong community support.

โ†’ ๐‚๐ฅ๐จ๐ฎ๐-๐‘๐ž๐š๐๐ฒ: MongoDB Atlas, the cloud version of MongoDB, offers automated deployments, backups, and monitoring, so you can focus on building your application.

Iโ€™m looking forward to diving deeper into MongoDB and sharing more insights as I progress through this challenge.
1721501998899

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ of 100DaysOfCode

  • ๐™’๐™๐™š๐™ฃ ๐™ฉ๐™ค ๐™ช๐™จ๐™š ๐˜ฟ๐™Š๐™ˆ๐˜พ๐™ค๐™ฃ๐™ฉ๐™š๐™ฃ๐™ฉ๐™‡๐™ค๐™–๐™™๐™š๐™™ -

->First, what is ๐˜‹๐˜–๐˜”๐˜Š๐˜ฐ๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต๐˜“๐˜ฐ๐˜ข๐˜ฅ๐˜ฆ๐˜ฅ?
๐˜‹๐˜–๐˜”๐˜Š๐˜ฐ๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต๐˜“๐˜ฐ๐˜ข๐˜ฅ๐˜ฆ๐˜ฅ is an event that is fired when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.

This event is useful when you want your JavaScript code to interact with the DOM as soon as it is available, ensuring that all the elements you might need to manipulate are accessible.

->Now, when to use ๐˜‹๐˜–๐˜”๐˜Š๐˜ฐ๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต๐˜“๐˜ฐ๐˜ข๐˜ฅ๐˜ฆ๐˜ฅ?

Running code raw (without ๐˜‹๐˜–๐˜”๐˜Š๐˜ฐ๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต๐˜“๐˜ฐ๐˜ข๐˜ฅ๐˜ฆ๐˜ฅ) is only feasible if you place your script at the end of the <body> tag. This ensures that the DOM is already loaded by the time the script executes. This method can make your HTML and JavaScript more concise and readable but requires careful placement.

This approach is suitable for simpler scripts or when you have a clear structure, ensuring the script is at the end of the <body> to guarantee the DOM is loaded.

For most scenarios, breaking your code into DOM-independent and DOM-dependent parts is advisable. This provides a balance between ensuring your DOM manipulations are safe and keeping your code efficient.

This approach involves dividing your code into DOM-dependent and DOM-independent parts. You place DOM-independent code (like variable declarations, function definitions, or initial computations) outside the ๐˜‹๐˜–๐˜”๐˜Š๐˜ฐ๐˜ฏ๐˜ต๐˜ฆ๐˜ฏ๐˜ต๐˜“๐˜ฐ๐˜ข๐˜ฅ๐˜ฆ๐˜ฅ event listener, and DOM-dependent code inside it.

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ‘ of 100DaysOfCode

  • :๐™๐™–๐™จ() & :๐™ฃ๐™ค๐™ฉ() ๐™จ๐™š๐™ก๐™š๐™˜๐™ฉ๐™ค๐™ง๐™จ -

โ†’ :๐˜ฉ๐˜ข๐˜ด Selector:
The :๐˜ฉ๐˜ข๐˜ด selector is a new addition to CSS that allows you to select an element if it contains a specific descendant. Itโ€™s essentially a parent selector, which weโ€™ve long been waiting for in CSS.

โ†’ :๐˜ฏ๐˜ฐ๐˜ต Selector:
The :๐˜ฏ๐˜ฐ๐˜ต selector is a CSS pseudo-class that allows you to exclude elements that match a certain condition. It helps in filtering out elements that you donโ€™t want to style.

โ†’ Combining :๐˜ฉ๐˜ข๐˜ด and :๐˜ฏ๐˜ฐ๐˜ต:
By combining these two selectors, you can create complex conditions for styling elements. For example, you can make a category filter using only HTML and CSS.

Below is a simple code that showcase the category filter example using the :has and :not selectors as well as :checked selector (returns true when a radio button / checkbox / option is checked or selected).

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ’ of 100DaysOfCode

  • ๐™‘๐™–๐™ง๐™ž๐™–๐™—๐™ก๐™š๐™จ ๐™ž๐™ฃ ๐˜พ๐™Ž๐™Ž -

Ever felt frustrated when you need to change a color or spacing value across multiple CSS rules? Say hello to CSS Variables!

โ†’ ๐—ช๐—ต๐—ฎ๐˜ ๐—ฎ๐—ฟ๐—ฒ ๐—–๐—ฆ๐—ฆ ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ๐˜€?
CSS Variables, also known as custom properties, allow you to store values (like colors, fonts, or sizes) in one place and reuse them throughout your stylesheet. They make your CSS cleaner, more maintainable, and super flexible.

โ†’ ๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐——๐—ฒ๐—ฐ๐—น๐—ฎ๐—ฟ๐—ฒ ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ๐˜€:
CSS variables are declared within a selector that defines their scope. They are typically defined in the โ€˜:๐ซ๐จ๐จ๐ญโ€™ pseudo-class to make them globally available throughout the document.

โ†’ ๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐—จ๐˜€๐—ฒ ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ๐˜€:
To use a CSS variable, you reference it with the ๐˜ท๐˜ข๐˜ณ() function.

โ†’ ๐—ช๐—ต๐˜† ๐—จ๐˜€๐—ฒ ๐—–๐—ฆ๐—ฆ ๐—ฉ๐—ฎ๐—ฟ๐—ถ๐—ฎ๐—ฏ๐—น๐—ฒ๐˜€?

  1. ๐Œ๐š๐ข๐ง๐ญ๐š๐ข๐ง๐š๐›๐ข๐ฅ๐ข๐ญ๐ฒ: Update the value in one place to change it everywhere.
  2. ๐‘๐ž๐ฎ๐ฌ๐š๐›๐ข๐ฅ๐ข๐ญ๐ฒ: Use the same value across multiple rules.
  3. ๐“๐ก๐ž๐ฆ๐ข๐ง๐ : Easily switch themes by updating variable values.
  4. ๐ƒ๐ฒ๐ง๐š๐ฆ๐ข๐œ ๐’๐ญ๐ฒ๐ฅ๐ข๐ง๐ : Change values dynamically with JavaScript.
    1721751706222
2 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ“ of 100DaysOfCode :tada:

  • ๐™๐™š๐™จ๐™ฅ๐™ค๐™ฃ๐™จ๐™ž๐™ซ๐™š ๐™‰๐™–๐™ซ๐™ž๐™œ๐™–๐™ฉ๐™ž๐™ค๐™ฃ ๐˜ฝ๐™–๐™ง -

Today, I challenged myself to build a fully responsive navigation bar from scratch using only HTML and CSS. At first it was challenging to make it work seamlessly across all devices.

However, it was possible thanks to the CSS property @๐™ข๐™š๐™™๐™ž๐™–(๐™ข๐™–๐™ญ-๐™ฌ๐™ž๐™™๐™ฉ๐™: x), which helps in applying styles based on the maximum width of the screen hence creating responsive web designs that look and function well on a variety of devices, from mobile phones to desktop computers.

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ” of 100DaysOfCode

  • ๐™‚๐™ง๐™–๐™™๐™ž๐™š๐™ฃ๐™ฉ ๐˜ฝ๐™ค๐™ง๐™™๐™š๐™ง๐™จ -

You probably think canโ€™t you just use any gradient function (linear-gradient for example) as a value for the border-color property?

The answer to that would be no, you canโ€™t.
So how can it be done?

Here is where the ::๐’ƒ๐’†๐’‡๐’๐’“๐’† & ::๐’‚๐’‡๐’•๐’†๐’“ pseudo elements come to play.

โ†’ ๐–๐ก๐š๐ญ ๐š๐ซ๐ž ๐ญ๐ก๐ž๐ฌ๐ž ๐ฉ๐ฌ๐ž๐ฎ๐๐จ-๐ž๐ฅ๐ž๐ฆ๐ž๐ง๐ญ๐ฌ?
The ::๐’ƒ๐’†๐’‡๐’๐’“๐’† & ::๐’‚๐’‡๐’•๐’†๐’“ pseudo elements in CSS are used to insert content before or after the content of an element. They are particularly useful for adding decorative or informative content without altering the HTML structure.

โ†’ ๐๐ฎ๐ญ ๐‡๐จ๐ฐ ๐œ๐š๐ง ๐ญ๐ก๐ž๐ฒ ๐ฎ๐ฌ๐ž๐ ๐Ÿ๐จ๐ซ ๐๐จ๐ซ๐๐ž๐ซ๐ข๐ง๐ ?
These pseudo-elements can be used to create gradient borders by positioning them absolutely around an element, applying a gradient background, and extending their dimensions slightly beyond the elementโ€™s borders. This setup creates the appearance of a border with gradient colors without altering the elementโ€™s original structure.

2 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ• of 100DaysOfCode

  • ๐™’๐™š๐™–๐™ฉ๐™๐™š๐™ง ๐˜ผ๐™ฅ๐™ฅ -

Hello community, for the next few days Iโ€™ll be sharing some mini JavaScript projects that Iโ€™ll working on.

Todayโ€™s Project is a ๐—ช๐—ฒ๐—ฎ๐˜๐—ต๐—ฒ๐—ฟ ๐—”๐—ฝ๐—ฝ.

The Weather App fetches real-time weather data from an API and displays it in a user-friendly format. Itโ€™s a great way to practice handling API requests and manipulating DOM elements.

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ– of 100DaysOfCode

  • ๐™๐™–๐™ฃ๐™™๐™ค๐™ข ๐™‹๐™–๐™จ๐™จ๐™ฌ๐™ค๐™ง๐™™ ๐™‚๐™š๐™ฃ๐™š๐™ง๐™–๐™ฉ๐™ค๐™ง -

The Random Password Generator creates secure passwords of varying lengths, ensuring a mix of uppercase, lowercase, numbers, and special characters. It also includes a convenient copy function to easily use the generated passwords.

Through this project, I learned about the navigator: clipboard property, the entry point to ๐—–๐—น๐—ถ๐—ฝ๐—ฏ๐—ผ๐—ฎ๐—ฟ๐—ฑ ๐—”๐—ฝ๐—ถ, which can be used to implement cut, copy, and paste features within a web application.

3 Likes

๐ƒ๐š๐ฒ ๐Ÿ๐Ÿ— of #100DaysOfCode

  • ๐™Œ๐™ ๐˜พ๐™ค๐™™๐™š ๐™‚๐™š๐™ฃ๐™š๐™ง๐™–๐™ฉ๐™ค๐™ง -

The QR Code Generator creates QR codes for any given text or URL. This tool is incredibly useful for quickly sharing information in a compact, scannable format.

Feel free to scan the code in video and let me know your results. :smile:

3 Likes