Skip to content

JS FAQ - JavaScript Guides Online

Get answers to your JavaScript questions. Explore detailed how-to guides, code examples, and best practices for beginners and developers.

  • Home
  • Home
Books
How to get the length of a string in JavaScript
Posted inStandard Objects: Array

How to get the length of a string in JavaScript

Posted inStandard Objects: ArrayTags: js string, length, size, string
Learn to accurately determine the length of a string in JavaScript, handling immutability, Unicode complexities, and using methods like Array.from for accurate results.
Read More
How to return a function from another function in JavaScript
Posted inClosures and Arrow Functions

How to return a function from another function in JavaScript

Posted inClosures and Arrow FunctionsTags: closures, higher-order, js closures, nested
JavaScript closures in loops using var can cause functions to share the same variable, leading to unexpected results. Use let for block-scoped bindings per iteration. Also, watch for memory leaks from closures retaining references to large objects or elements.
Read More
How to export a function from a module in JavaScript
Posted inModules and Imports

How to export a function from a module in JavaScript

Posted inModules and ImportsTags: export, function, js modules, module
Default exports hinder JavaScript module refactoring by allowing arbitrary import names, complicating IDE updates. Named exports enable automatic renames and improve code discoverability, boosting efficiency and consistency. Always use named exports for better maintainability.
Read More
How to send a POST request with fetch in JavaScript
Posted inFetch API and AJAX

How to send a POST request with fetch in JavaScript

Posted inFetch API and AJAXTags: fetch, form submit, js fetch, post
A common fetch mistake is assuming a resolved promise means success. The fetch API does not reject on HTTP errors like 404 or 500. You must check the response.ok property to handle server errors. For robust error handling, parse the JSON body on failures to get specific messages from the API.
Read More
How to run tests with Jest from the command line
Posted inUnit Testing: Jest

How to run tests with Jest from the command line

Posted inUnit Testing: JestTags: cli, command, jest, run
Jest flags: --watch for Git-tracked changes, --watchAll for all files, --runInBand for serial debugging, --clearCache for errors, --findRelatedTests for specific files. Configure moduleNameMapper for path aliases. Debug with node --inspect-brk. Use jest.useFakeTimers() for timer tests.
Read More
How to use bitwise operators in JavaScript
Posted inAdvanced Topics

How to use bitwise operators in JavaScript

Posted inAdvanced TopicsTags: binary, bitwise, logic, operators
JavaScript bitwise operator precedence, &, ^, | lower than ==/!=; always parenthesize (options & FLAG) == FLAG. Signed 32-bit interpretation: use >>> 0 or debugBits to view hex. Bitwise truncates to 32-bit; use BigInt for >32-bit. Avoid ~indexOf; use includes.
Read More
How to run tests from the command line in JavaScript
Posted inTesting Frameworks

How to run tests from the command line in JavaScript

Posted inTesting FrameworksTags: automation, cli, testing
Prevent broken merges with Git pre-commit hooks using husky and lint-staged for Jest tests and ESLint. Implement a server-side CI pipeline with GitHub Actions. Enforce passing tests before merging to the main branch with branch protection rules, making it impossible to merge broken code.
Read More
How to fill shapes with color on canvas in JavaScript
Posted inCanvas and WebGL

How to fill shapes with color on canvas in JavaScript

Posted inCanvas and WebGLTags: canvas, fillStyle, js graphics, shapes
Canvas drawing issues with overlapping shapes caused by missing beginPath() in HTML5 Canvas API. Without beginPath(), multiple shapes merge into one continuous path, causing unwanted stroke and fill behavior. Proper use of beginPath() separates shapes for independent styling in canvas graphics.
Read More
How to define a callback function in JavaScript
Posted inAsynchronous JavaScript

How to repeat execution using setInterval in JavaScript

Posted inAsynchronous JavaScriptTags: async, js async, loop, setInterval
JavaScript setInterval best practices. Use recursive setTimeout for async polling and data fetching. Prevent request pile-ups. Manage timers with the Page Visibility API for background tabs. Abstract logic with custom hooks like useInterval to avoid memory leaks from forgotten clearInterval calls.
Read More
How to send a POST request using Axios
Posted inLibraries: Axios

How to send a POST request using Axios

Posted inLibraries: AxiosTags: axios, body, post, request
Axios response object structure: data, status, headers. Detailed Axios error handling: the error object, error.response for server status codes, and error.request for network failures. Code examples using async/await with try/catch for robust JavaScript applications.
Read More

Posts pagination

Previous page 1 … 28 29 30 31 32 … 35 Next page
Copyright 2026 — JS FAQ - JavaScript Guides Online. All rights reserved.
Scroll to Top