Alaa Taima
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # what is a modularization?** Modular programming is the process of subdividing a computer program into separate sub-programs can often be used in a variety of applications and functions with other components of the system. ![](http://aosd.net/wp-content/uploads/2017/11/Modular-Programming-diagram.jpg) # ** Why is it a good idea to modularise your code?** - Less code has to be written, its simple and easy to understand. A single procedure can be developed for reuse, eliminating the need to retype the code many times. - Programs can be designed more easily because a small team deals with only a small part of the entire code. - Enables multiple programmers to divide up the work and debug pieces of the program independently. - Enforce logical boundaries between components and improve maintainability (every modular application has a version number associated with it). - Make a testable code as it mimimize the dependency between the units. - Errors can easily be identified, as they are localized to a subroutine or function. - Teams can develop modules separately and do not require knowledge of all modules in the system. - The same code can be used in many applications. - The scoping of variables can easily be controlled. ![](https://techbeacon.scdn7.secure.raxcdn.com/sites/default/files/2017-07-05_09_37_03-if_i_2_count_35_i_0_._blogmd_-_sublime_text.png) # Wrapper function: Even if you define a global variable in a module using var, let or const keywords, the variables are scoped locally to the module rather than being scoped globally. This happens because each module has a function wrapper of its own and the code written inside one function is local to that function and cannot be accessed outside this function. ![](https://cdn-media-1.freecodecamp.org/images/jrHUpyWccEG3RTJQg54GR78bbJw6FxN6cWtf) ![](https://cdn-media-1.freecodecamp.org/images/ppIlxCPf-ko2PaAXyhiOqckmoNtcyHKeYCs1) # module.exports: The module parameter (rather a keyword in a module in Node) refers to the object representing the current module. exports is a key of the module object, the corresponding value of which is an object. The default value of module.exports object is {} (empty object). You can check this by logging the value of module keyword inside any module. ### -it is used for defining stuff that can be exported by a module: ` module.exports['key'] = nameOfTheFunction; ` or Adding all of them at once by using object: ` module.exports={ firstFunc:FirstFunction, secondFun:SecondFunction } ` ### Require: require keyword refers to a function which is used to import all the constructs exported using the module.exports object from another module. -The value returned by the require function in module y is equal to the module.exports object in the module x. const variableToHoldExportedStuff = require('idOrPathOfModule'); -What do you think will happen if I try to access the variable named PI defined in module A inside module B without exporting it from module A? pi = undefined *So, you may be wondering why you didn’t get a ReferenceError. This is because you are trying to access a key named PI inside the module.exports object returned by the require function. You also know that the key named PI does not exist in the module.exports object. Note that when you try to access a non-existent key in an object, you get the result as undefined. This is the reason why you get PI as undefined instead of getting a ReferenceError. ## Why should you use asyncronous forms of functions with Node? * For non-blocking code execution. * To make any code unit independent and to make it continue outside of the ongoing flow of the main code. ## When might you use the syncronous ? ```javascript function () { array.forEach(function(data) { fs.writeFile(data) }); // do this after forEach has finished looping, not after files have finished being writen to } function () { array.forEach(function(data) { fs.writeFileSync(data) }); // do this after all files have been written to } ``` ## What is fs and how can we use fs-module used by requiring it: * used to access physical file system : * const fs = require('fs'). * provides useful functions to interact with the file system : - 1- Read files - 2- Create files : </br> ```javascript [ fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) { if (err) throw err; console.log('Saved!'); }); ] ``` - 3- Update files : </br> fs.appendFile),(fs.writeFile()) - 4- Delete files : </br> fs.unlink() - 5- Rename files </br> fs.rename ## All the methods of (FS) are asynchronous by default, but they can also work synchronously by appending Sync. : * fs.rename() * fs.renameSync() * fs.write() * fs.writeSync() ## The Path module provides a way of working with directories and file paths. * var filename = path.basename('/Users/Refsnes/demo_path.js'); * var filename = path.basename('/Users/Refsnes/demo_path.js', 'js'); * var directories = path.dirname('/Users/Refsnes/demo_path.js'); * var ext = path.extname('/Users/Refsnes/demo_path.js'); # Working with url : A URL - Uniform Resource Locator - more commonly known as a "web address". ## What is URL ? A URL is human-readable text that was designed to replace the numbers (IP addresses) that computers use to communicate with servers. They also identify the file structure on the given website. A URL consists of a protocol, domain name, and path (which includes the specific subfolder structure where a page is located) and has the following basic format: ```javascript protocol://domain-name.top-level-domain/path ``` * The protocol indicates how a browser should retrieve information about a resource. The web standard is http:// or https:// (the "s" stands for "secure"), but it may also include things like mailto: (to open your default mail client) or ftp: (to handle file transfers). * The domain name (or hostname): is the human-readable name of the specific location where a resource (in most cases, a website) is located. * top-level domain (TLD) as something of a category for websites. While you're likely familiar with .com, there is also .edu for educational sites, .gov for governmental sites, and many, many more. * URLs also contain things like the specific folders and/or subfolders that are on a given website, any parameters (like click tracking or session IDs) that might be stored in the URL, and anchors that allow visitors to jump to a specific point in the resource. ## URL Object URL is a namespace used to host 2 static methods used to manipulate URLs using Blobs: * URL.createObjectURL(): </br> static method creates a DOMString containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object. </br> > Syntax : ```javascript objectURL = URL.createObjectURL(object); ``` > Parameters : </br> object: A File, Blob or MediaSource object to create an object URL for. > Return value : DOMString -UTF-16 String- * URL.revokeObjectURL() : </br> static method releases an existing object URL which was previously created by calling URL.createObjectURL(). Call this method when you've finished using an object URL to let the browser know not to keep the reference to the file any longer. > Syntax : ```javascript window.URL.revokeObjectURL(objectURL); ``` > Parameters : </br> objectURL : A DOMString > Return value : Void ```javascript urlObject({'url':'http://localhost.test?name=ayman&age=22&gpa=3.5&course=programming&course=mathematics&course=algorithms'}); { "protocol": "http:", "hostname": "localhost.test", "host": "localhost.test", "port": "", "hash": "", "pathname": "/", "search": "?name=ayman&age=22&gpa=3.5&course=programming&course=mathematics&course=algorithms", "parameters": { "name": "ayman", "age": 22, "gpa": 3.5, "course": [ "programming", "mathematics", "algorithms"] } } ``` ## Why is it important to be able to turn JavaScript objects into querystrings and back again? Query string in URL is very useful to work with dynamic content. Generally, server-side language is used to get query string from URL. But you can also get query string parameters from URL to client-side. The query string parameters and values can be easily retrieved from the URL using JavaScript. ## How to Get Query String Parameters from URL using JavaScript: Assume URL is : ```javascript http://codexworld.com/index.php?type=product&id=1234 ``` Get Query String Parameters : Use location.search to get query string parameters including the question mark (?). ```javascript var queryString = location.search; // ?type=product&id=1234 ``` Get Query String Parameter Value : ```javascript var urlParams = new URLSearchParams(location.search); urlParams.has('type'); // true urlParams.get('id'); // 1234 urlParams.getAll('id'); // ["1234"] urlParams.toString(); // type=product&id=1234 ``` ## How to Write Valid URL Query String Parameters * When building web pages, it is often necessary to add links that require parameterized query strings. For example, when adding links to the various validation services. * writing valid URL query string parameters, but there are easier, more efficient ways to produce valid, dynamic links. ## Build a query string manually from other strings is A Bad Idea ? One of the reasons these links aren’t validating is because they contain non-encoded ampersand ( & ) characters. Ampersands are often used in URL query strings to demarcate granular chunks of information, for example: ```javascript http://domain.tld/function.cgi?url=http://fonzi.com/&name=Fonzi&mood=happy&coat=leather ``` To get this code to validate, we need to encode the ampersands with &amp;, for example: ```javascript http://domain.tld/function.cgi?url=http://fonzi.com/&amp;name=Fonzi&amp;mood=happy&amp;coat=leather ``` Replacing the ampersand characters with encoded equivalents does not change the functionality of the query string, but it does produce completely valid code. * Encode other special characters a blank space is equivalent to “%20” ```javascript <a href="http://delicious.com/post?url=http://domain.tld/&amp;title=The%20title%20of%20a%20post">Bookmark at Delicious</a> ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully