#49MediumQuiz
49. What's the difference between feature detection, feature inference, and using the UA string?
BrowserJavaScript
Feature detection directly checks if an API exists; feature inference assumes unrelated APIs from one check; UA sniffing parses navigator.userAgent.
Example 1:
supportsFeature({ IntersectionObserver: () => {} }, "IntersectionObserver"); // true
supportsFeature({}, "ShareAPI"); // falsesolution.js
Detects supported API on environment object
expect(supportsFeature({ IntersectionObserver: function () {} }, "IntersectionObserver")).toBe(true)