Introduction
Welcome to your first lesson in your journey to mastering JavaScript for QA automation. Your goal is to build a strong, foundational understanding of the language from the ground up, and our starting point will be the most direct and powerful tool for exploring JavaScript: the browser's developer console.
In this lesson, you will learn how to use the developer console to execute simple JavaScript expressions. Think of the console as your personal laboratory for JavaScript. It allows you to write and run code instantly, without any complex setup, making it the perfect environment to experiment and get immediate feedback. This hands-on approach will be central to our "no spoon-feeding" philosophy, enabling you to see cause and effect in real-time. By the end of this session, you'll be comfortable opening the console, writing basic commands, and understanding how JavaScript processes them.
Your Interactive JavaScript Environment
Every modern web browser, like Chrome, Firefox, or Safari, comes with a built-in suite of "Developer Tools." One of the most important parts of this suite is the Console. The console is an interactive environment that allows you to communicate directly with the browser's JavaScript engine.
It operates on a simple but powerful principle called a REPL, which stands for Read-Evaluate-Print Loop.
- Read: The console reads the line of JavaScript code you type in.
- Evaluate: The JavaScript engine interprets and executes your code, figuring out what it means and calculating a result.
- Print: The console displays the result of the evaluation.
- Loop: The console then waits for your next command, completing the loop.
This loop provides instant feedback, which is invaluable for learning and debugging. As a QA engineer, you're familiar with the process of providing an input and verifying an output; the console works in a very similar way, making it an intuitive tool for testing code snippets.
Getting Started: Opening the Console
Let's begin by opening the console. The process is slightly different depending on your browser. The following resource provides clear instructions for Chrome, Firefox, and Safari.
JavaScript in the browser console (Creative Coding)
This guide will walk you through opening the developer console in your browser.
Please read the section titled Bringing up the console. For the best experience, I recommend using Google Chrome for these lessons, but any modern browser will work. Follow the instructions to open the console on a blank browser tab.
Once you have the console open, you'll see a blinking cursor next to a > symbol. This is the command line, ready to accept your JavaScript code.

Expressions, Evaluation, and Values
Now that you have the console open, it's time to write some code. The fundamental building blocks of JavaScript programs are expressions. An expression is any piece of code that the JavaScript engine can evaluate to produce a single value.
The article you just reviewed provides a great mental model for this.
JavaScript in the browser console (Creative Coding)
This section explains the core concepts of expressions and evaluation.
In the same article, read the part titled Read, evaluate, print, loop. Focus on understanding the relationship: Expression → Evaluation → Value.
Let's put this into practice. The simplest expressions are literal values themselves. Type the following into your console and press Enter:
42
The console will print 42 back to you. The expression was 42, and since it already is a value, the evaluation just results in 42.
Now, let's try something more complex: an arithmetic expression. Type this into your console:
5 + 15
The console will print 20. Here:
- The expression is
5 + 15. - The evaluation is the process of performing the addition.
- The value is the result,
20.
Exploring Different Types of Expressions
The console can handle much more than simple addition. You can use it to explore a wide variety of JavaScript expressions. The following reading and exercises will guide you through arithmetic, comparisons, and even built-in functions.
JavaScript in the browser console (Creative Coding)
This resource provides hands-on examples of various expressions you can run. As you read, be sure to type the code examples directly into your console to see the results for yourself.
Please read the following sections from the "JavaScript in the browser console" article: Start with Arithmetic expressions to learn the basic operators (+, -, *, /) and the importance of order of operations using parentheses. Next, read Expressions of inequality. Here you'll see expressions that evaluate to the boolean values true or false. These are fundamental for decision-making in code. Continue to Built-in functions. This introduces the concept of calling a function, which is another type of expression. Now, tackle the challenge in A six-sided die. This section is particularly important as it shows how you can combine, or "nest," multiple expressions to achieve a more complex result. Pay close attention to the final expression, Math.floor(Math.random() * 6) + 1, and try to reason through why it works. Finally, read the short section on Alert! to see a function that performs an action (a "side effect") and learn about text values, which are called strings.
After working through those examples, you've already interacted with several core concepts:
- Numbers:
42,8.5 - Operators:
+,*,> - Booleans:
true,false - Strings:
"Hello, world!" - Functions:
Math.random(),Math.floor(),alert()
The difference between the console printing a return value (like 4) and a function causing a side effect (like alert() showing a pop-up) is a subtle but critical concept that we will revisit many times. For now, simply observe that some commands produce a value directly in the console, while others do things that affect the browser outside the console.
Conclusion
In this lesson, you've taken your first crucial step into the world of JavaScript. You learned that the browser console is an interactive playground (a REPL) that lets you execute code and see the results instantly. You are now able to open the console and use it to run various kinds of expressions—from simple arithmetic to more complex combinations of function calls. Most importantly, you have established a foundational mental model: you write an expression, the browser evaluates it, and it produces a value.
Key Takeaways:
- The browser developer console is a REPL: Read-Evaluate-Print Loop.
- An expression is any valid unit of code that resolves to a single value.
- You can execute arithmetic (
5 * 10), comparison (17 > 18), and function call (Math.random()) expressions in the console. - Expressions can be combined to perform more complex tasks.
In our next lesson, we will build directly on this foundation. You've seen how to create values by evaluating expressions, but they disappear as soon as you're done. Next, you'll learn how to declare variables to store those values, allowing you to save and reuse them throughout a program.