JavaScript
Lecture-1
Introduction to JavaScript
● ECMAScript (or ES) is a JavaScript standard meant to ensure the
interoperability of web pages across different web browsers. It is
standardized by Ecma International according to the document
ECMA-262.
● ECMAScript 2015 was the second major revision to JavaScript.
● ECMAScript 2015 is also known as ES6 and ECMAScript 6.
2
Where to Compile and Run codes?
● On Browser
● On local(Node Js)
3
Statements & Comments
console.log(‘hi’);
var a = 5;
if (a === 5) {
console.log('value of a is 5');
}
// this is a comment
/* this is another comment */
/**
* this is a
* multiline comment
*/
4
Variables
var a = 5;
let b = 6;
const myName = “Khan”;
const areWeReady = true;
let fifthLetter = ‘e’;
var passMarks = 33.00;
● Why we are using var, let, and const for doing the same thing?
● What are the differences among these three???
● Can we put a space between fifth and Letter??
● Can’t we just name it like 5thLetter?
5
Operators
let a = 7;
let b = 4;
let c = a + b;
● Arithmetic Operators
● Assignment Operators
● Comparison Operators
● Conditional Operators
● Type Operators
6
Arithmetic Operators
● + Addition
● - Subtraction
● * Multiplication
● / Division
● % Modulus
● ** Exponentiation(^)
● ++ Increment
● -- Decrement
7
Assignment Operators
● = p=q p=q
● += p += q p=p+q
● -= p -= q p=p-q
● *= p *= q p=p*q
● /= p /= q p=p/q
● %= p %= q p=p%q
● **= p **= q p = p ** q
8
Comparison Operators
● == equal to
● === equal value and equal type
● != not equal
● !== not equal value or not equal type
● > greater than
● < less than
● >= greater than or equal to
● <= less than or equal to
● ? ternary operator
9
Conditional Operators
● && logical and
● || logical or
● ! logical not
10
Type Operators
● typeof Returns the type of a variable
● instanceof Returns true if an object is an instance of an object type
11
Data Types
1. String
2. Number
3. Bigint
4. Boolean
5. Symbol
6. Object (Object, Array, Date)
7. Undefined
8. Null
12
Conditional Statements
const num1 = 5;
const num2 = 6;
if (num1 === num2) {
console.log("Numbers are equal");
} else if (num1 > num2) {
console.log("Number1 is greater than number2");
} else {
console.log("Number1 is less than number2");
}
13
Conditional Statements
const jerseyNum = 7;
const jerseyColor = 'white';
if (jerseyNum === 7 && jerseyColor === 'white') {
console.log('got the player');
} else {
console.log('not found');
}
14
Conditional Statements
const marks = 110;
if (marks > 100 || marks < 0) {
console.log("Invalid input");
} else if (marks <= 100 && marks >= 80) {
console.log("Your grade is A");
} else if (marks < 80 && marks >= 70) {
console.log("Your grade is B");
} else if (marks < 70 && marks >= 60) {
console.log("Your grade is C");
} else {
console.log("Your grade is D");
}
15
Conditional Statements
const marks = -10;
let grade = null;
if (marks > 100 || marks < 0) {
console.log("Invalid input");
} else if (marks <= 100 && marks >= 80) {
grade = "A";
} else if (marks < 80 && marks >= 70) {
grade = "B";
} else if (marks < 70 && marks >= 60) {
grade = "C";
} else {
grade = "D";
}
if (grade !== null) {
console.log(`Your grade is ${grade}`);
}
16
Conditional Statements
const jerseyNum = 7;
const jerseyColor = "white";
let found = false;
if (jerseyNum === 7) {
if (jerseyColor === "white") {
found = true;
}
}
if (found === true) {
console.log("got the player");
} else {
console.log("not found");
}
17
Conditional Statements
const a = 4;
const b = 6;
const c = 5;
let max = a;
if (max < b) {
max = b;
}
if (max < c) {
max = c;
}
console.log(max);
18
Thank you
19