JS Interview Question: What’s the difference between feature detection, feature inference, and using the UA string?

These 3 are just practices of determining if a certain web technology feature exists in a user’s browser or environment. Though features may vary with not just modern web technology but with programming languages as well.

Feature Detection
Feature detection is just a way of determining if a feature exists in certain browsers. A good example is a modern HTML5 feature ‘Location’.

if (navigator.geolocation) {
// detect users location here B-) and do something awesome

Feature Inference
Feature Inference is when you have determined a feature exists and assumed the next web technology feature you are implementing unto your app exists as well. Its usually bad practice to assume, so its better to explicitly specify features you want to detect and plan a fallback action.

UA String
UA String or User Agent String is a string text of data that each browsers send and can be access via navigator.userAgent. These “string text of data” contains information of the browser environment you are targeting.
If you open your console and run


You’ll see it outputs a “string text of data” containing complete information of the environment you are currently using. Since this is an old way of doing detection, this method can be easily spoofed, thus, may not be the best route to take. Ref: https://en.wikipedia.org/wiki/User_agent

A JavaScript library I love using is Modernizr

Modernizr is a small piece of JavaScript code that automatically detects the availability of next-generation web technologies in your user’s browsers. Rather than blacklisting entire ranges of browsers based on “UA sniffing,” Modernizr uses feature detection to allow you to easily tailor your user’s experiences based on the actual capabilities of their browser.


If you are looking for a platform to develop your clients’ website, check out my SAAS platform https://ecompurpl.com

EcomPurpl.com is the all-in-one solution for anyone looking to create a website. Templates, E-Commerce, Hosting, Galleries, Booking & Appointments, CRM, 24/7 support, and integration of your app are all included.




Software Engineer / Front-End Dev. Currently resides in Las Vegas. https://ecompurpl.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Story Time: My Quarantine Days

Angular: Monitor element is in viewport after scrolling

Angular 2.0 vs Polymer

Track performance of your web application with JavaScript

Introduction to React Hooks

CallMask Beta Version is released

Wallet Page

Writing standard RESTful API & nodejs (practical example).

Java vs JavaScript: Here’s What You Need To Know

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
RLyn Ben

RLyn Ben

Software Engineer / Front-End Dev. Currently resides in Las Vegas. https://ecompurpl.com

More from Medium

Conditional (ternary) operator in Javascript

JavaScript Design Patterns #1: Single Responsibility Principle

JavaScript syntax for CRUD operations

Front End Developer — Entry Level Interview Question.

Image of Code in Computer