Hot Posts

Model 6

Document

Perfect 👍 we’ve covered:
✅ Module 1: .NET Core & ASP.NET
✅ Module 2: ASP.NET MVC
✅ Module 3: Web API
✅ Module 4: SQL
✅ Module 5: HTML & CSS

Now let’s move to:


✅ Module 6: JavaScript


6.1 What is JavaScript?

  • JavaScript (JS) is a client-side scripting language used to add interactivity, control DOM, validate forms, and communicate with servers (AJAX).

  • Runs in all modern browsers.


6.2 Variables in JavaScript

  • var → function-scoped, can be redeclared.

  • let → block-scoped, modern way.

  • const → block-scoped, cannot be reassigned.

Example:


var a = 10;
let b = 20;
const c = 30;

6.3 Data Types

  • Primitive → string, number, boolean, null, undefined, symbol, bigint.

  • Objects → arrays, functions, date, custom objects.

Example:


let name = "John";        // string
let age = 25;             // number
let active = true;        // boolean
let user = {id:1, name:"John"}; // object

6.4 Functions

  • Normal Function


function add(a, b) {
   return a + b;
}
  • Arrow Function


let add = (a, b) => a + b;

6.5 DOM Manipulation

  • DOM (Document Object Model) → JS can change HTML structure dynamically.

Common Methods:

  • document.getElementById("id")

  • document.querySelector(".class")

  • element.innerHTML = "Text";

  • element.style.color = "red";

Example:


document.getElementById("btn").onclick = function() {
   document.getElementById("msg").innerHTML = "Button Clicked!";
}

6.6 Events in JavaScript

  • onclick, onchange, onmouseover, onkeyup.

Example:




6.7 JSON (JavaScript Object Notation)

  • Lightweight data format for APIs.


let student = { "id":1, "name":"John", "marks":85 };
console.log(student.name); // John

6.8 Loops

  • for, while, do while, for...of, for...in.


for(let i=0; i<5; i++) {
   console.log(i);
}

6.9 Array & String Methods

  • Arrays: push(), pop(), map(), filter(), reduce().

  • Strings: length, toUpperCase(), substring(), split().


6.10 ES6 Features

  • Template Literals:

    
    let name = "John";
    console.log(`Hello ${name}`);
    
  • Destructuring:

    
    let [a,b] = [1,2];
    
  • Spread Operator:

    
    let arr = [1,2,3];
    let arr2 = [...arr, 4,5];
    

6.11 Form Validation Example







📌 Summary for Module 6:

  • JavaScript handles interactivity, DOM, events, validation.

  • Revise var vs let vs const, arrow functions, JSON, array methods.

  • Be able to write simple form validation.