Master Basic JavaScript Practice Exercises With These 10 Essential Coding Drills

Bobby Jul 13, 2026

Embarking on a journey to master JavaScript? Congratulations! You've taken the first step towards equipping yourself with one of the most in-demand coding languages. To solidify your understanding, engaging in basic JavaScript practice exercises is crucial. This article will guide you through fundamental exercises that will not only enhance your skills but also enhance your portfolio.

Free JavaScript Practice for Beginners: 8 Best JavaScript Exercise Sites
Free JavaScript Practice for Beginners: 8 Best JavaScript Exercise Sites

Before diving into the practical exercises, let's briefly recap the basics. JavaScript is a high-level, interpreted programming language primarily used for web development, along with HTML and CSS. It's the heart of web interactivity, enabling dynamic web content and functionality. Now, let's move on to the exercises that will help you grasp these fundamental concepts.

JavaScript basic - Exercises, Practice, Solution - w3resource
JavaScript basic - Exercises, Practice, Solution - w3resource

JavaScript Basics

Before we delve into more complex exercises, let's ensure you're comfortable with the building blocks of JavaScript. These basic exercises will help you understand the core concepts and lay a strong foundation for your coding journey.

Practice Javascript: 160 Solved Exercises to Accelerate your Learning
Practice Javascript: 160 Solved Exercises to Accelerate your Learning

Remember, the best way to learn is by doing. So, grab your JavaScript IDE or simply use the browser's developer console, and let's get started!

Variables and Data Types

JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)

Your first exercise should focus on understanding variables and data types in JavaScript. Variables are containers for storing data values, while data types define the kind of data a variable can hold. Start by declaring variables of different data types: numbers, strings, booleans, null, and undefined.

For example: ```javascript let name = "John Doe"; // String let age = 30; // Number let isStudent = false; // Boolean let car; // Undefined (initialized but not assigned a value) let bike = null; // Null (no value, but intentionally set) ```

Operators and Expressions

Learn JavaScript Step by Step
Learn JavaScript Step by Step

Operators are symbols that perform operations on variables and values. There are several types of operators in JavaScript, including arithmetic, assignment, comparison, logical, and more. Practice using these operators to create expressions that manipulate and evaluate data.

Here's an exercise that involves creating an expression to calculate the area of a rectangle: ```javascript let length = 10; let width = 5; let area = length * width; // Expression using multiplication operator console.log(area); // Outputs: 50 ```

Control Structures

Best Way to Learn JavaScript in 2024 (Free and Paid Tutorials)
Best Way to Learn JavaScript in 2024 (Free and Paid Tutorials)

Control structures in JavaScript determine the order in which code is executed based on certain conditions. Familiarizing yourself with control structures is essential for creating dynamic and interactive web applications.

Let's delve into two fundamental control structures: if-else statements and loops (for and while).

Javascript Cheet cheet
Javascript Cheet cheet
JavaScript Basics You MUST Know
JavaScript Basics You MUST Know
JavaScript exercises: Functions
JavaScript exercises: Functions
How to Create a Function in JavaScript: Step-by-Step Guide 🚀
How to Create a Function in JavaScript: Step-by-Step Guide 🚀
The JavaScript Cheat Sheet Every Beginner Wishes They Had
The JavaScript Cheat Sheet Every Beginner Wishes They Had
JavaScript Projects That Will Make You Better Fast 😳
JavaScript Projects That Will Make You Better Fast 😳
JS Functions 5 Min Guide for Beginners
JS Functions 5 Min Guide for Beginners
the operator's manual for programming
the operator's manual for programming
JavaScript
JavaScript
JavaScript Basics | Chapter 1 📖 | Part 1
JavaScript Basics | Chapter 1 📖 | Part 1
JavaScript Basics: The Essential Guide for Beginners 🚀
JavaScript Basics: The Essential Guide for Beginners 🚀
Javascript String Methods
Javascript String Methods
Javascript Fundamental
Javascript Fundamental
3 Ways to Define Functions in JavaScript
3 Ways to Define Functions in JavaScript
What is JavaScript? How to Learn JavaScript Fast? - Mikke Goes
What is JavaScript? How to Learn JavaScript Fast? - Mikke Goes
JavaScript Full Notes Every Beginner Must Save 💡
JavaScript Full Notes Every Beginner Must Save 💡
JavaScript Basics for Beginners | Learn JS Step by Step
JavaScript Basics for Beginners | Learn JS Step by Step
Functions in Javascript
Functions in Javascript
Coding with Parvez
Coding with Parvez
a poster with different types of projects and instructions for students to use in the classroom
a poster with different types of projects and instructions for students to use in the classroom

Conditional Statements (if-else)

if-else statements allow your code to make decisions based on given conditions. Write a program that takes a user's age as input and categorized them into different age groups using if-else statements.

Here's a simple example: ```javascript let age = prompt("Enter your age"); if (age <= 12) { console.log("You are a child."); } else if (age > 12 && age <= 19) { console.log("You are a teenager."); } else { console.log("You are an adult."); } ```

Loops (for and while)

Loops allow you to repeat a block of code multiple times. Practice using for and while loops to iterate through arrays and perform repetitive tasks.

Here's an exercise that uses a for loop to list all even numbers between 1 and 20: ```javascript for (let i = 1; i <= 20; i++) { if (i % 2 === 0) { console.log(i); } } ```

Functions and Arrays

Functions are reusable blocks of code that perform specific tasks, while arrays are ordered collections of values, which can hold multiple data types. Mastering functions and arrays will significantly improve your coding efficiency and versatility.

Let's explore two practical exercises to help you understand these concepts better.

Function Basics

Write a function that greets a person by their name. This function should accept a name as an argument and return a greeting message. For an extra challenge, modify the function to greet the person using their preferred title (Mr., Ms., Dr., etc.) and take the title as an optional argument.

Here's a simple example: ```javascript function greet(name, title = "Mr.") { return `${title} ${name}, how are you?`; } console.log(greet("John Doe", "Mr.")); // Outputs: Mr. John Doe, how are you? ```

Arrays and Methods

Practice creating and manipulating arrays using various array methods. Start by creating an array of your favorite colors. Then use some of the following methods to manipulate the array: push(), pop(), shift(), unshift(), sort(), reverse(), and splice(). Remember to log the array after each operation to observe the changes.

For example: ```javascript let colors = ["red", "blue", "green"]; colors.push("yellow"); // Adds "yellow" to the end of the array colors.shift(); // Removes the first element ("red") from the array console.log(colors); // Outputs: [ 'blue', 'green', 'yellow' ] ```

Now that you've explored basic JavaScript practice exercises, it's time to challenge yourself with more complex problems. Websites like LeetCode, HackerRank, and CodeSignal offer a vast array of coding challenges to help you refine your skills. Don't forget to track your progress and celebrate your accomplishments along the way. Happy coding!