Why does a tester need to learn JavaScript

JavaScript is settled in minds as a language that is mostly applied to programming logic of user interface on the client side (web browser). This is what the language was intended for originally, and in 1995, thank to Netscape company, the idea (that had been stewing in different sauces for a few years by that moment) got the practical cut. Afterwards other browser vendors (after several attempts to invent their proprietary script languages) introduced JavaScript into their products as well. Now it is de facto the mandatory attribute of modern web application.

Is JavaScript used in web browsers only?

No, not only in web browsers. JavaScript is used wherever they need simple but flexible scenarios which would be able to manage objects of the environment. JavaScript support is introduced in such products like LibreOffice, MS Office, graphical tools of Adobe, GNOME desktop of Linux, Node.js which is a platform for sever-side development and many more. JavaScript is even used in microcontroller programming (for example some vendors that supply microcontrollers for elevators use JavaScript in their devices).

Okay, I’m a tester. Why do I need JavaScript?

Most often QA engineers face JavaScript when they test web applications. Understanding of the language principles, being able to read the code and to write and debug simple things might help a tester to:

  • Understand principles and technology that underlies dynamically generated user interface. Dynamic user interface (the interface that might change depending on certain conditions) can be implemented as with help of CSS (however in such case you will be quite limited in how "dynamic" it could be), as with help of JavaScript. Such code on the client side evaluates current conditions and rebuilds the layout when detects changes. For example, with the help of JavaScript it is possible to detect change of view port size and reassign styles (defines in CSS) to the elements or generate new styles for elements (hide or show elements, enable or disable fields, change the size or/and position of elements, etc.).

  • Understand principles and technology that underlies asynchronous user interface. When work asynchronously, different parts of page might refresh the state and data from server independently from each other. It’s achieved by JavaScript-code opens and maintains another dedicated connection to the server and on some expected event it refreshes only particular DOM part (e.g. a widget) it is responsible for.

  • Understand hidden logic of application. It often happens that testers receive very poor requirements or do not get requirements at all. It also happens that analyzing the code is the only way to understand the logic of application without having any sort of requirements. Such analysis helps to approach test design more effectively (in aspect of test data preparation) and in general to detect risky areas of application. It will also help you to assist your developers in issue root cause detection and hence to grow your professional reputation.

  • Use advanced techniques of test automation. Some types of user-to-web page interactions are impossible to implement with the help of only bindings for chosen programming language (for example screen scrolling, creating custom elements within the page on test run time, DOM analysis, etc.). Disclaimer: You should use advanced techniques of test automation with caution and always have a good understanding of what you’re doing and why. Otherwise there is a high probability of missing important defects.

  • Test for vulnerabilities. Some common web application vulnerabilities are caused by the specific of JavaScript-code execution within browsers. For example, Cross-site Scripting (or XSS) vulnerability (as per OWASP project assessment) in 2017 was detected in one third of all tested applications worldwide.

  • Expand the variability of test automation frameworks used. Selenium has a number of alternatives (and that number is growing from year to year). Some alternatives (like Cypress) use JavaScript as the primary language for coding automated tests.

This list is not exhaustive. There is nearly infinite number of cases in which the engineer that knows JavaScript can make their lives easier and make their tasks (manual and automated) simpler. If you still have questions, feel free to ask them here. I’ll add missing points to my post basing on your feedback.