Basic JavaScript Instructions, Statements, Comments,
Variables, Data Types, Arrays, Strings, Functions, Methods &
Objects, Decisions & Loops.
Module 1
Introduction to JavaScript
• JavaScript is a scripting language used for web
development.
• Runs in the browser and allows interactive
content.
JavaScript Syntax
• JavaScript syntax includes variables, operators,
and expressions.
• Example: let x = 10 + 5;
Statements & Comments
• Statements define actions.
• Comments are used for explanations and
ignored by the interpreter.
• // This is a single-line comment
• /* Multi-line comment */
Variables
• Variables store data.
• Three types: var, let, const.
• Example: let userName = 'Alice';
Data Types
• Primitive: Number, String, Boolean, Null,
Undefined.
• Reference: Object, Array, Function.
Numbers in JavaScript
• JavaScript supports integers and floating-point
numbers.
• Example: let num = 10.5;
Strings
• Strings store text.
• Methods include length, slice, toUpperCase.
• Example: let greeting = 'Hello';
String Manipulation
• Concatenation: let fullName = firstName + ' ' +
lastName;
• Extracting: let firstChar = name[0];
Arrays
• Arrays store multiple values.
• Example: let fruits = ['apple', 'banana',
'cherry'];
• Access with index: fruits[0]
Array Methods
• Methods include push, pop, shift, unshift,
slice.
• Example: [Link]('mango');
Functions
• Functions encapsulate reusable code.
• Example: function add(a, b) { return a + b; }
Function Types
• Function Declaration: function greet()
{ [Link]('Hello'); }
• Function Expression: let greet = function()
{ [Link]('Hi'); };
Objects
• Objects store key-value pairs.
• Example: let person = {name: 'John', age: 25};
Object Methods
• Objects can contain methods.
• Example: [Link] = function()
{ [Link]('Hello ' + [Link]); };
Decisions - If Statements
• If statements control flow.
• Example: if (age > 18) { [Link]('Adult'); }
Decisions - Switch
• Switch statements evaluate expressions.
• Example: switch(day) { case 'Monday':
[Link]('Start of week'); break; }
Loops - For
• For loops iterate a set number of times.
• Example: for(let i = 0; i < 5; i++)
{ [Link](i); }
Loops - While
• While loops run until a condition is false.
• Example: while(count < 10) { count++; }
Loops - Do While
• Executes at least once before checking
condition.
• Example: do { count++; } while (count < 10);
Events in JavaScript
• Events trigger actions.
• Example: [Link] = function()
{ alert('Clicked!'); }
DOM Manipulation
• JavaScript interacts with HTML elements.
• Example:
[Link]('demo').innerHTM
L = 'Hello';
Error Handling
• Try-Catch handles errors.
• Example: try { [Link](); } catch(err)
{ [Link]('Error!'); }