Writing Your First Test


Writing your first test is an important step toward becoming a professional developer.

A test checks whether a piece of code gives the expected result.  

Instead of guessing if your function works, you let the test confirm it for you.

In this lesson, you will learn how to write simple tests without any library so you clearly understand the core idea of testing.

What a Simple Test Includes

  • Input values
  • Expected output 
  • Actual output from the function
  • A check to compare both  

If expected and actual values match, the test passes.  
Otherwise, the test fails.

This function adds two numbers.

Now we will write a test to make sure it always works correctly.

The test calls the function and compares the result with the expected value.

If both match, the test passes.

These examples show how easy it is to start testing your code.

By writing even simple tests, students gain the habit of verifying their work — a key mindset of professional developers who build reliable and high-quality JavaScript applications.