Understanding feature detection
Days are gone when there were simple JavaScript codes utilizing limited browser features, and a website would not be very complex. These days, a developer needs canvas, audio and video, geographic location of the user, drag and drop, and many more features to implement all needed requirements. Unfortunately, not all browsers support all of these features in their latest versions.
In case a feature is not supported, a developer writes a cross-browser script, which either first detects a browser or if a feature is present, and then executes suitable code for that browser. This task is very challenging as detecting a browser is not always reliable. You detect a browser, and then make an assumption that the feature will be present, which might not always be correct. An older version of browser may not support a feature or a newer version may drop a feature. You will learn about browser detection and why it is not a good practice later in this chapter.
The other...