3. JavaScript Core: The Logic Layer
JavaScript: Making the Web Think
HTML is the skeleton. CSS is the skin. JavaScript is the brain. It is a full programming language that runs directly inside the browser, allowing you to manipulate data, react to user clicks, and fetch information from servers. In this massive module, we break down every core building block of the language.
Variables: The `const` Keyword
Variables are containers for storing data. Modern JavaScript relies heavily on const. You use const when you declare a variable that should NEVER be reassigned to a completely new value later in the code.
Variables: The `let` Keyword
Use let when you know the variable's value will need to change over time (like a score in a game, or a counter).
Data Types: Strings & Template Literals
Strings represent text. While you can use single or double quotes, modern JS favors Template Literals (using backticks `). They allow you to easily inject variables directly into the text.
Data Types: Numbers & Booleans
Numbers handle all math. Booleans are strict binary values: exactly true or exactly false. They are the core of decision-making logic.
Data Types: Arrays
An Array is a single variable used to store an ordered list of multiple items. Arrays are zero-indexed, meaning the first item is at position 0.
Data Types: Objects
Objects are used to store collections of data in key-value pairs. They represent real-world entities much better than isolated variables.
Functions: Traditional Declarations
A function is a block of code designed to perform a particular task. It is reusable. You define it once, and "call" it whenever you need it.
Functions: Arrow Functions
Introduced in ES6, Arrow Functions provide a shorter, cleaner syntax for writing functions. They are used extensively in modern libraries like React.
DOM Manipulation: Selecting Elements
The Document Object Model (DOM) is JavaScript's representation of your HTML. To change the HTML with JavaScript, you first have to find the specific element.
DOM Manipulation: Event Listeners
JavaScript sits and waits for things to happen. These things are called Events (clicks, scrolling, typing). You attach an Event Listener to an element to run a function when the event occurs.
Knowledge Check
Ready to test your understanding of 3. JavaScript Core: The Logic Layer?