Skip to content
Parwaz DigitalMarketing · Web · Courses

Web Development Course · Module 3, lesson 1

JavaScript variables and data types

Write your first JavaScript: declaring variables with let and const, working with strings, numbers and booleans, and using the browser console.

What you will learn

  • Declare variables with const and let and know when to use each
  • Work with strings, numbers, booleans, null and undefined
  • Run and debug code using the browser console

JavaScript is the programming language of the browser. You can add it to a page with a <script> element, ideally pointing to a separate file and placed with the defer attribute so it runs after the HTML has loaded. To experiment quickly, open the console in developer tools and type code directly. console.log() prints values there and is your first debugging tool.

Variables store values. Use const for values that will not be reassigned, such as const shopName = "Sunrise Bakery", and let for values that change, such as a counter. Prefer const by default and switch to let only when you need to reassign. The older var keyword still works but has confusing scoping rules, so modern code avoids it.

JavaScript has several basic types. Strings hold text in quotes, numbers hold both whole numbers and decimals, and booleans are true or false. undefined means a value has not been set, and null means it has been deliberately left empty. Template literals, written with backtick characters, let you insert values into text, for example ${price} inside a sentence. The typeof operator tells you a value's type.

Practice task

In the browser console, create constants for a product name, price and stock count, then use a template literal to log a sentence such as "Croissant costs 250 rupees, 12 left".

Web Development Course

Learn this properly,with a final project.

These pages summarise each lesson. The full course teaches them hands-on. Message us for the current fee, schedule, and format.

Available for new projects — Replies within one business day