Modern JavaScript Course
Modern JavaScript (ES6+ Features)
Modern JavaScript (ES6 and beyond) introduced powerful features that make code cleaner and
more efficient.
Arrow Functions
Shorter syntax for writing functions.
// Traditional function
function add(a, b) {
return a + b;
}
// Arrow function
const add = (a, b) => a + b;
Use arrow functions when you want concise function expressions, especially for callbacks.
Template Literals
Use backticks (`) to create strings that can include variables.
const name = "Tafadzwa";
[Link](`Hello, ${name}!`); // Output: Hello, Tafadzwa!
Multiline strings are easier with template literals:
const greeting = `Welcome to
JavaScript ES6!`;
Destructuring
Extract values from arrays or objects into variables.
// Array destructuring
const [a, b] = [10, 20];
[Link](a); // 10
// Object destructuring
const person = { name: "Anna", age: 30 };
const { name, age } = person;
[Link](name); // Anna
Exploring the DOM More Deeply
Beyond getElementById, you can use other powerful DOM methods:
Selecting Elements
[Link](".my-class")
[Link]("p")
[Link]("my-class")
[Link]("div")
Creating and Appending Elements
const newItem = [Link]("li");
[Link] = "New List Item";
[Link]("ul").appendChild(newItem);
Changing Attributes
[Link]("img").setAttribute("src", "[Link]");
Event Listeners, Timers, and Form Validation
Event Listeners
Used to attach behavior to DOM elements.
const button = [Link]("button");
[Link]("click", () => {
alert("Button clicked!");
});
Timers
Use setTimeout and setInterval for delayed and repeated actions.
setTimeout(() => {
[Link]("Runs once after 2 seconds");
}, 2000);
setInterval(() => {
[Link]("Runs every 1 second");
}, 1000);
Form Validation
<form id="myForm">
<input type="email" id="email" required>
<button type="submit">Submit</button>
</form>
<p id="error"></p>
[Link]("myForm").addEventListener("submit", function(e) {
const email = [Link]("email").value;
if () {
[Link]();
[Link]("error").textContent = "Please enter a valid email.";
}
});
More Mini Projects
To-Do List
Add tasks
Mark as complete
Delete tasks
Calculator
Build a simple calculator using buttons and input fields.
Quiz App
Ask questions
Score user
Show results with feedback
Introduction to JavaScript Frameworks and Libraries
[Link]
React is a JavaScript library for building user interfaces.
Component-based
Reusable code
Managed state
Fast performance using virtual DOM
[Link]
[Link] allows you to run JavaScript on the server.
Build APIs
Work with databases
Handle HTTP requests
Use [Link] for web servers