Overview
This course teaches JavaScript from beginner to advanced level, focusing on building interactive web projects, including an Amazon-like e-commerce site, using JavaScript along with HTML and CSS.
JavaScript Fundamentals
- JavaScript makes websites interactive, working alongside HTML (content) and CSS (appearance).
- Code instructions are written in a browserβs console or within HTML files using the
<script> element.
- JavaScript syntax must be precisely followed; errors cause code to break (syntax errors).
- JavaScript can handle popups (alert), math operations, and webpage modification.
Numbers, Math, and Order of Operations
- JavaScript uses operators (+, -, *, /) for arithmetic; follows standard order of operations (multiplication/division before addition/subtraction).
- For money, calculate in cents to avoid floating-point inaccuracies, then convert to dollars.
- Use
Math.round() to round numbers to the nearest integer.*
Strings and Text Handling
- Strings represent text, created with single quotes, double quotes, or backticks (template strings).
- Strings can be concatenated or constructed with interpolation using
${} in template strings.
- Escape characters (
\', \", \n) handle special characters and new lines in strings.
HTML & CSS Integration
- HTML structures web content with elements and tags; elements can be nested.
- CSS styles elements using selectors (by element or class), properties, and values.
- The
class attribute labels elements for styling or JavaScript selection.
- The structure
<html>, <head>, and <body> is standard for HTML files.
Variables and Data Types
- Variables store values using
let, const (preferred, for constants), or var (legacy, avoid).
- Variables are reassigned with
=, and naming follows camelCase convention.
- Types include numbers, strings, and booleans (
true, false).
Booleans and Control Flow
- Booleans result from comparisons (
===, !==, <, >, etc.).
if, else if, else statements control program flow based on conditions.
- Logical operators:
&& (and), || (or), ! (not).
- Falsy values:
false, 0, "", NaN, undefined, null.
Functions and Scope
- Functions group code for reuse, declared with
function and called by name.
- Parameters pass input, and
return provides output; scope limits variable access.
- Functions can be stored in objects as methods.
Objects and Arrays
- Objects group related values and functions using key-value pairs.
- Arrays store ordered lists of values, accessed by index.
- Use array methods:
push (add), splice (remove), forEach, map, filter.
- Destructuring and shorthand syntax make code concise.
The DOM (Document Object Model)
- The DOM allows JavaScript to select and modify webpage elements.
- Use
document.querySelector() to get elements, then change .innerHTML or .innerText.
- Add event listeners with
.addEventListener() for interactivity.
Advanced Features
- External libraries (via
<script> or modules) add reusable code.
- Modules (
export/import) help organize and prevent naming conflicts.
- Promises,
async/await manage asynchronous code (like HTTP requests with fetch).
Testing and Debugging
- Manual testing: interact with the website to check behavior.
- Automated testing: write code to test code (with or without frameworks like Jasmine).
- Use assertions (expectations) and organize tests by functionality.
Object-Oriented Programming (OOP)
- OOP organizes code into objects using classes, constructors, and methods.
- Inheritance allows child classes to reuse parent class code.
- Private properties (
#) restrict access to class internals.
- Polymorphism allows methods to be called on objects, regardless of their specific class.
Backend, HTTP, and Async Code
- Backends manage website data and communicate via HTTP requests (get, post, put, delete).
- Use
fetch (preferred) or XMLHttpRequest in JavaScript for HTTP calls.
- URL parameters pass data between pages (e.g., for tracking orders).
Key Terms & Definitions
- Variable β Named storage for values (
let, const, var).
- Boolean β Value representing true or false.
- Array β Ordered list of values.
- Object β Key-value collection of data.
- Function β Reusable block of code.
- Class β Blueprint for creating objects in OOP.
- DOM β JavaScript object representing the webpage structure.
- Module β Isolated file exporting/importing code to avoid conflicts.
- Promise β Object representing future completion of an async operation.
- Fetch β Modern API for HTTP requests in JavaScript.
- Callback β Function passed as an argument to be run later.
- Event Listener β Function called in response to user actions like clicks.
- Test Suite β Collection of related tests.
- MVC β Model-View-Controller pattern for organizing code.
Action Items / Next Steps
- Complete exercises at the end of each lesson for practice.
- Try converting objects to classes and implement inheritance.
- Build and test a to-do list, calculator, and rock-paper-scissors game.
- Use backend APIs with
fetch() and URL parameters.
- Explore further with Node.js and deploying websites online.