I’d like to share some useful JavaScript code snippets I have saved that I think can help make your life as a developer easier.
Hi there, my name is Rahul, and I am 18 years old, learning development and designing sometimes.
Today, I’d like to share some useful JavaScript code snippets I have saved that I think can help make your life as a developer easier.
Let’s get started!
Generate a random number between two values: const randomNumber = Math.random() * (max – min) + min
Check if a number is an integer: const isInteger = (num) => num % 1 === 0
Check if a value is null or undefined: const isNil = (value) => value === null || value === undefined
Check if a value is a truthy value: const isTruthy = (value) => !!value
Check if a value is a falsy value: const isFalsy = (value) => !value
Check if a value is a valid credit card number:
Check if a value is an object: const isObject = (obj) => obj === Object(obj)
Check if a value is a function: const isFunction = (fn) => typeof fn === ‚function‘
Remove Duplicated from Array const removeDuplicates = (arr) => […new Set(arr)];
Check if a value is a promise: const isPromise = (promise) => promise instanceof Promise
Check if a value is a valid email address:
Check if a string ends with a given suffix: const endsWith = (str, suffix) => str.