JavaScript Study Notes

Introduction to JavaScript

  • JavaScript is essential for web applications (2025/26).

Variables

  • Use var for global/local variables; let for block-scoped.

  • Syntax example: var n = 1; sumDoubled = function(m) {...}.

Functions

  • Functions can be assigned to variables.

  • Example: let sum_up_to = function(n) {...}.

  • Function declaration can use function name(parameters) {...}.

Control Statements

  • Includes if, switch, loops (for, while).

  • Use === for strict equality and !== for strict inequality.

Loops

  • while and for loops demonstrate iteration.

    • Example: while (count < 10) {...}.

Data Types

  • Simple types: Numbers, Strings, Booleans.

  • Objects: Functions (e.g., let square = function(n) {...}).

Object Manipulation

  • Access properties via dot notation or bracket notation.

  • Example: let person = { fname: "Lisa", lname: "Simpson" }.

Constructors & Classes

  • Define constructors with uppercase names and the new keyword.

  • New class syntax introduced in ES6: class Color { ... }.

Exception Handling

  • Use try and catch for handling exceptions.

    • Keyword throw to initiate exceptions.

Arrays

  • Dynamic size, use methods like push, splice for manipulation.

    • Arrays can be initialized using let arr = [].

Client-Side JavaScript

  • Runs in browsers; allows interactive HTML documents.

  • Javascript can be included directly in HTML using <script> tag.

jQuery Basics

  • Simplifies DOM manipulation and event handling.

  • Example: $(document).ready(function() {...}); for DOM readiness.

Event Handling

  • Attach actions/events to elements (click, focus, change).

  • Use the on method for various user interactions.