1

I brow some code in javascript, found some code of function like that

function isPromise(obj) {
  return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
}

As what I say to the title, why this function use !!obj" ??

Abson
  • 81
  • 4

1 Answers1

1

If you are referring to "double bang" in JavaScript it is a force coercion falsely or truthy to its boolean true or false

See this answer: What is the !! (not not) operator in JavaScript?

Jacob
  • 586
  • 6
  • 27