Javascript Lesson

Jul 21, 2024

Javascript Lesson

Introduction to Javascript

  • Introduction to JavaScript programming language (incomplete due to background noise).

Variables and Data Types

  • Variables are essential in programming to store data and manipulate it.
  • Key terms:
    • const - declares a constant variable.
    • let - declares a block-scoped local variable.
    • var - declares a function-scoped or globally-scoped variable.
  • Data types in Javascript:
    • Number
    • String
    • Boolean
    • Object
    • Undefined
    • Null

Operators

  • Arithmetic operators:

    • + (addition)
    • - (subtraction)
    • * (multiplication)
    • / (division)
    • % (modulus)
  • Assignment operators:

    • = (assignment)
    • += (addition assignment)

UI Elements in HTML

  • Creating buttons in HTML using <input type="button">
  • Example:
    <input type="button" value="Click me">
    

Arrays in Javascript

  • Declaring arrays and adding elements.
    • Example: const animals = ['cat', 'dog', 'elephant'];
    • Accessing array elements using indices.
    • Array methods.

Inspecting Elements

  • Right-clicking and selecting "Inspect" in the browser to open Developer Tools.

DOM Manipulation

  • Selecting elements by ID using document.getElementById().
  • Adding and manipulating elements.
  • Example:
    let element = document.getElementById('myElement');
    element.innerText = 'Hello, world!';
    

Object-Oriented Programming (OOP) in Javascript

  • Concepts of OOP:

    • Class
    • Object
    • Methods
    • Properties
  • Example of a class in Javascript:

    class Employee {
        constructor(name, position, salary) {
            this.name = name;
            this.position = position;
            this.salary = salary;
        }
        getDetails() {
            return `${this.name} is a ${this.position} earning ${this.salary}`;
        }
    }