Back in the early days of the internet, web pages were static, meaning they they contained text and images that were displayed on the screen but didn’t change or interact with the user. Of course, only so much that is interesting can happen with static content. Several different technologies were developed to facilitate dynamic web pages. JavaScript is one of these technologies.
JavaScript is a programming language. Many web servers host programs written in JavaScript, which are sent to devices as part of the web page. The device runs the JavaScript on its local processor and follows the commands of the program, which can animate images on the website, popup a menu, and do many other useful things.
Of course, the concept of running arbitrary programs from a website is potentially dangerous. So there are limitations placed on JavaScript to keep it from doing things like installing viruses. However, it turns out that these limitations are overly broad. Below is a screenshot from webkay, which is a website that demonstrates the type of information that JavaScript can produce about a device. Browser Leaks is another good resource.
For privacy purposes, the ideal would be to browse the internet with JavaScript disabled. However, there are some websites that legitimately require JavaScript to accomplish their purposes and others that don’t work correctly without JavaScript even though they could be programmed to do so. Privacy Browser addresses this by making it easy to toggle JavaScript on and off. Tapping the privacy shield will toggle it between blue or yellow (both of which indicate that JavaScript is disabled) and red (JavaScript enabled). Looking at the different information webkay can collect with JavaScript enabled and disabled is informative.
Browsing the internet with JavaScript disabled, and only enabling it if needed, goes a long way toward protecting privacy. In addition, JavaScript is used to load much of the annoying advertisements and extra cruft that comes along with most modern websites. With it disabled, websites will load faster, consume less network traffic, and use less CPU power, which leads to longer battery life.