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.


