Lesson goal: Explain what JavaScript is and identify common uses.
To understand what JavaScript is, think about an online shopping page. When you change the quantity of a product from one to three, the total price updates. This means you have interacted with the page, and it has responded to your action.
JavaScript is a programming language often used to create this kind of behavior on websites. In fact, it helps make web pages interactive and engaging.
A programming language allows us to write instructions that a computer can follow. With JavaScript, these instructions might calculate a total, check an answer, or change a message shown on the screen. Therefore, it is an essential tool for web development.
| Website feature | How JavaScript can help |
|---|---|
| Shopping cart | Recalculate a total when the quantity changes. |
| Online quiz | Check an answer and update the score accordingly. |
| Search box | Display suggestions while someone types in the box. |
| Student dashboard | Update progress information based on user input. |
| Registration form | Show custom feedback about an entered value. |
| Weather page | Request weather data and display the result dynamically. |
These examples illustrate how JavaScript enhances website features. A complete website may also use server-side code or databases. In addition, built-in browser features are important as well.
For instance, a browser can check whether a required form field is empty using HTML alone. However, JavaScript allows us to add more specific behavior, which improves user experience.
In this course, your JavaScript will run within a web browser.
The browser includes a JavaScript engine. This is the part that reads and executes JavaScript instructions. You do not need to install JavaScript separately to run the examples in this section.
JavaScript can also run outside a browser; however, we will focus on executing code in web pages first.
console.log("Welcome to NHPlearning!");
The console is a developer tool where you can read messages, run small pieces of code, and investigate errors. We will explore it further in Lesson 1.3.
console.log tells the browser to display a console message immediately.The message appears in the console, not in the visible content of the web page.
JavaScript and Java are different programming languages. Therefore, you do not need to learn Java before starting this course.
Choose a website you use often. Write down two features that could use JavaScript effectively.
Example:
On a learning website, JavaScript could check a quiz answer and update a progress bar.
Quick Check
What could JavaScript do in a student marks calculator?
Answer: Read entered marks, calculate a result, and display it.
JavaScript lets you write instructions that allow web pages to respond and perform tasks. In this course, you will start by running small programs in your browser. As a result, you will gain hands-on experience.
Practical task: Create a simple student profile page and print a welcome message in the console.
Checkpoint: Students can connect their script correctly and find its output.