{"id":22349062,"url":"https://github.com/afsify/javascript","last_synced_at":"2025-08-17T12:38:30.422Z","repository":{"id":215473466,"uuid":"739026024","full_name":"afsify/javascript","owner":"afsify","description":"Enhance your JavaScript proficiency with a curated set of exercises, guiding you seamlessly from basics to advanced concepts. Dive into hands on exercises for a complete grasp of JavaScript mastery.","archived":false,"fork":false,"pushed_at":"2024-10-29T12:02:45.000Z","size":57,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T14:33:49.998Z","etag":null,"topics":["important","javascript","workouts"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/afsify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-04T15:49:27.000Z","updated_at":"2024-10-29T12:02:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"3329cfc7-a31e-4403-9981-11fd0c7ce72e","html_url":"https://github.com/afsify/javascript","commit_stats":null,"previous_names":["mhdafs/javascript","afsify/javascript"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/afsify/javascript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afsify%2Fjavascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afsify%2Fjavascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afsify%2Fjavascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afsify%2Fjavascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afsify","download_url":"https://codeload.github.com/afsify/javascript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afsify%2Fjavascript/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267822076,"owners_count":24149562,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["important","javascript","workouts"],"created_at":"2024-12-04T11:07:15.267Z","updated_at":"2025-07-30T06:31:10.904Z","avatar_url":"https://github.com/afsify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaScript\n\nJavaScript is single threaded and synchronous by default. This means that it has a single main thread of execution, and each operation is performed one at a time in a sequential manner. The term \"single threaded\" indicates that JavaScript code is executed in a single sequence or order, and each operation is completed before the next one begins.\n\nThe global execution context is the top level or outermost context in which JavaScript code is executed. When a JavaScript program starts running, the global execution context is created, providing a global scope for variables, functions, and other constructs.\n\n**Call Stack:**\n\n- The call stack is a data structure that keeps track of function calls in the program.\n- When a function is called, it is added to the top of the call stack. When a function completes, it is       removed from the stack.\n\n**Callback Queue:**\n\n- JavaScript uses a callback queue to manage asynchronous operations and events.\n- Asynchronous tasks, such as timers, network requests, or user interactions, are handled by the browser or runtime environment.\n- When an asynchronous task is complete, its callback function is pushed into the callback queue.\n\n**Event Loop:**\n\n- The event loop constantly checks two main structures: the call stack and the callback queue.\n- If the call stack is empty, the event loop takes the first function from the callback queue and pushes it onto the call stack for execution.\n- This process ensures that asynchronous tasks do not block the main thread and that their associated callback functions are executed when the call stack is clear.\n\n## Best Practices for JavaScript Coding\n\nBelow are some of the best practices that can be followed while JavaScript coding in order to make your code cleaner, shorter, and easier to read.\n\n## Semicolons in Statements\n\nJavaScript statements do not strictly require semicolons at the end, but it is always a good practice to end them with a semicolon.\n\n```JavaScript\nlet x = 5;\nconsole.log(x);\n```\n\n## Meaningful Variable Names\n\nUse meaningful names for variables. For boolean variables, consider adding 'is' at the beginning, such as `isComplete`, `isLoaded`, etc.\n\n```JavaScript\nlet isComplete = true;\nlet isLoaded = false;\n```\n\n## Avoid Redundancy in Naming\n\nAvoid redundancy in naming objects and their properties. For example, consider an object like 'employee'.\n\nAvoid declaring\n\n```JavaScript\nlet employee = {\n  employeeId:1,\n  employeeName:”John”,\n  employeeSalary:50000\n}\n```\n\nInstead declare as\n\n```JavaScript\nlet employee={\n  id:1,\n  name:”John”,\n  salary:50000\n}\n```\n\n## Variable Declarations\n\n- Use `var` for variable declarations when you want them to get hoisted to the top of the program.\n- Use `let` for variable declarations that will change their value over time and to have block scope.\n- Use `const` for variables that don't need to be reassigned.\n\n```JavaScript\nconsole.log(hoistedVar); // Output: undefined\nvar hoistedVar = \"I can be hoisted!\";\nconsole.log(hoistedVar); // Output: I can be hoisted!\n```\n\n## Global Variable Declaration\n\nAvoid global declaration of variables for security concerns and optimal memory utilization.\n\n## Strict Comparisons\n\nUse '===' instead of '==' for strict comparisons.\n\n```JavaScript\nlet num = 5;\nif (num === \"5\") {\n  console.log(\"Strict comparison\");\n} else {\n  console.log(\"Not strictly equal\");\n}\n```\n\n## Comments\n\nAdd comments wherever necessary for documentation purposes, but avoid commenting out code.\n\n```JavaScript\n// This is a single-line comment\n\n/*\n  This is a\n  multi-line comment\n*/\n```\n\n## Arrow Functions\n\nUse arrow functions in place of function expressions whenever you want to preserve the lexical value of 'this'. Arrow functions have a shorter syntax, helping to keep the code clean, shorter, and more readable.\n\n```JavaScript\nlet add = (a, b) =\u003e a + b;\n```\n\n## Template Literals\n\nUse template literals to construct strings with special characters, to concatenate strings and values, and to preserve newlines.\n\n```JavaScript\nlet name = \"John\";\nlet greeting = `Hello, ${name}!`;\n```\n\n## Destructuring\n\nUse destructuring syntax to extract values from objects and arrays, reducing the number of lines of code and not modifying the original object/array values.\n\n```JavaScript\nlet person = { firstName: \"John\", lastName: \"Doe\" };\nlet { firstName, lastName } = person;\n```\n\n## Rest Operator\n\nUse the rest operator when passing an indefinite amount of arguments to a function.\n\n```JavaScript\nfunction sum(...numbers) {\n  return numbers.reduce((acc, num) =\u003e acc + num, 0);\n}\n```\n\n## Spread Operator\n\nUse the spread operator when passing a set of variables to a function from an array and when concatenating arrays.\n\n```JavaScript\nlet arr1 = [1, 2, 3];\nlet arr2 = [...arr1, 4, 5];\n```\n\n## Async-Await\n\nUse async-await instead of promises or callbacks to keep the code short, clean, and more readable.\n\n```JavaScript\nasync function fetchData() {\n  return new Promise((resolve) =\u003e {\n    setTimeout(() =\u003e {\n      resolve(\"Data fetched successfully!\");\n    }, 1000);\n  });\n}\n\nasync function processData() {\n  try {\n    const data = await fetchData();\n    console.log(data);\n  } catch (error) {\n    console.error(\"Error:\", error);\n  }\n}\n```\n\n## JavaScript Classes\n\nUse JavaScript classes to write cleaner and simpler code.\n\n```JavaScript\nclass Dog {\n  constructor(name, age) {\n    this.name = name;\n    this.age = age;\n  }\n\n  bark() {\n    console.log(\"Woof!\");\n  }\n}\n```\n\n## For..of Loop\n\nUse the for..of loop instead of traditional for loops to iterate over the values of an array, making the code cleaner and shorter.\n\n```JavaScript\nlet numbers = [1, 2, 3, 4, 5];\nfor (let number of numbers) {\n  console.log(number);\n}\n```\n\n## JavaScript Security Best Practices\n\nBelow are some of the security best practices to be considered during JavaScript coding in order to safeguard the application from different security attacks.\n\n1. **Keep Code Up to Date:**\n   - Regularly update your codebase to include the latest security patches and fixes.\n\n2. **Use Latest Frameworks or Libraries:**\n   - Utilize up-to-date or the latest version frameworks or libraries for building applications.\n\n3. **Use Latest Version Browser:**\n   - Ensure the use of the latest version of web browsers to benefit from the latest security features.\n\n4. **Safe Handling of Cookies:**\n   - Cookies should be saved and used securely.\n   - Avoid persisting sensitive or critical information in cookies.\n   - Set proper expiry dates for cookies.\n   - Consider encrypting information stored in cookies.\n\n5. **Avoid using eval() Function:**\n   - Refrain from using the `eval()` function as it can be misused by attackers to execute malicious code.\n\n6. **Use Linters:**\n   - Linters help avoid coding mistakes during development, improving code quality.\n   - Examples of commonly used linters: JSLint, JSHint, ESLint.\n\n7. **JavaScript Security Analyzers:**\n   - Utilize tools that perform code analysis on client-side applications to identify vulnerabilities.\n   - Helps in writing secure code to prevent common security attacks.\n\n8. **JavaScript Obfuscation:**\n   - Employ obfuscation techniques to convert JavaScript code into a more secure form, preventing various types of attacks.\n\n## Clone the Repository\n\nIn the terminal, use the following command:\n\n```bash\ngit clone https://github.com/afsify/javascript.git\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafsify%2Fjavascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafsify%2Fjavascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafsify%2Fjavascript/lists"}