• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Archives for Miscellaneous

Miscellaneous

Check if the provided value is of the specified type

Check if the provided value is of the specified type

Compare the constructor property on the value with type to check if the provided value is of the specified type.

Miscellaneous

Show a custom context menu at clicked position

Show a custom context menu at clicked position

Sometimes, we want to replace the default right-click menu with our own menu that allows user to perform additional actions.

Miscellaneous

Add characters to the end of a string if it’s less than a certain length

Add characters to the end of a string if it’s less than a certain length

Accepts two arguments: the length the string should be, and what characters to add if it’s not that length.

Miscellaneous

Find a Specific Element from an Array

Find a Specific Element from an Array

Use find() method to find an element matching a specific criterion

Miscellaneous

Add characters to the beginning of a string if it’s less than a certain length

Add characters to the beginning of a string if it’s less than a certain length

Accepts two arguments: the length the string should be, and what characters to add if it’s not that length.

Miscellaneous

Short-Circuit Evaluation Using &&

Short-Circuit Evaluation Using &&

Instead of having to check if something is true with an if statement, you can use the && operator:

Miscellaneous

Combine two arrays using the spread operator

Combine two arrays using the spread operator

This syntax can also be used instead of pushing values to an array: Source https://medium.com/geekculture/20-javascript-snippets-to-code-like-a-pro-86f5fda5598e

Miscellaneous

Check if the user color scheme preference is dark

Check if the user color scheme preference is dark

Use Window.matchMedia() with the appropriate media query to check the user color scheme preference.

Miscellaneous

Cast Any Value to a Boolean

Cast Any Value to a Boolean

In JavaScript, you can use !! to convert anything to boolean.

Miscellaneous

Remove an attribute from an element

Remove an attribute from an element

Remove an attribute (including data attributes) on an element. This method can also be used to manipulate other types of attributes.

Miscellaneous

  • « Go to Previous Page
  • Go to page 1
  • Interim pages omitted …
  • Go to page 9
  • Go to page 10
  • Go to page 11
  • Go to page 12
  • Go to page 13
  • Interim pages omitted …
  • Go to page 16
  • Go to Next Page »

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers