undefined
JS-0126 1/* eslint-disable @typescript-eslint/no-explicit-any */
2export const debounce = (callback: any, wait: number) => {
3 let timeoutId: number | undefined = undefined; 4 return (...args: any[]) => {
5 window.clearTimeout(timeoutId);
6 timeoutId = window.setTimeout(() => {
In JavaScript, a variable that is declared and not initialized to any value automatically gets the value of undefined. For example:
var foo;
console.log(foo === undefined); // true
It's therefore unnecessary to initialize a variable to undefined
, such as:
var foo = undefined;
It's considered a best practice to avoid initializing variables to undefined
.
var foo = undefined;
let bar = undefined;
var foo;
let bar;
const baz = undefined;