Menu

gitpiper

isPromiseLike javascript Code Snippet in 2024

typefunctionpromiseintermediate

Last Updated: 17 December 2024

Checks if an object looks like a Promise.

  • Check if the object is not null, its typeof matches either object or function and if it has a .then property, which is also a function.
const isPromiseLike = obj => obj !== null && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
isPromiseLike({ then: function() { return ''; } }); // true isPromiseLike(null); // false isPromiseLike({}); // false

javascript snippet similar to isPromiseLike For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️