SlideShare a Scribd company logo
JavaScript Basics
PLAN
1. Intro to JS
2. JavaScript Integration with a html page
3. Js Variables
4. Js Operators
5. Js Functions
6. Loops
7. Switch
8. Js Events
9. Js Classes
WHY STUDY JAVASCRIPT?
JavaScript is one of the 3 languages all web
developers must learn:
1. HTML to define the content of web pages
2. CSS to specify the layout of web pages
3. JavaScript to program the behavior of web pages
EXAMPLES
INTRODUCTION
▪ JavaScript was designed to add interactivity to HTML pages
▪ JavaScript is a scripting language - a scripting language is a lightweight
programming language
▪ JavaScript is an interpreted language (means that scripts execute without
preliminary compilation)
▪ JavaScript is supported by all major browsers
▪ The language is dynamically typed
▪ No need to declare the type of a variable
▪ The type of a variable can change over time
JAVASCRIPT INTEGRATION WITH A HTML
PAGE
1. Inside the HTML File
2. As a external File
Inside Html File
▪ We can put js inside a script tag
▪ It can included in head or body
of the file
External Js file
• It separates HTML and code
• It makes HTML and JavaScript
easier to read and maintain
• Cached JavaScript files can speed
up page loads
• Use script tag and src attribute
HOW TO RUN JS
▪ Using browser developer tools(testing purpose only)
▪ Using html page
JS VARIABLES
Using var
▪ Variables defined with var can be
Redeclared.
▪ Variables defined with var can be
Declared after use.
▪ Variables defined with var do not
have a Block Scope.
Using let
▪ Variables defined
with let cannot be Redeclared.
▪ Variables defined with let must
be Declared before use.
▪ Variables defined with let have
Block Scope.
const
▪ Variables defined with const cannot be Redeclared.
▪ Variables defined with const cannot be Reassigned.
▪ Variables defined with const have Block Scope.
OPERATORS
FUNCTIONS
▪ A JavaScript function is a block of code designed to
perform a particular task.
▪ A JavaScript function is executed when "something"
invokes it (calls it).
• When an event occurs (when a user clicks a button)
• When it is invoked (called) from JavaScript code
• Automatically (self invoked)
function name(parameter1, parameter2, parameter3) {
// code to be executed
}
LOOPS
•for - loops through a block of code a number of times
•for/in - loops through the properties of an object
•for/of - loops through the values of an iterable object
•while - loops through a block of code while a specified condition is true
•do/while - also loops through a block of code while a specified condition is true
THE FOR LOOP
for (statement 1; statement 2; statement 3) {
// code block to be executed
}
▪ Statement 1 is executed (one time) before the
execution of the code block.
▪ Statement 2 defines the condition for executing the
code block.
▪ Statement 3 is executed (every time) after the code
block has been executed.
THE FOR IN LOOP
for (key in object) {
// code block to be executed
}
▪ Loops over properties of a object
THE FOR OF LOOP
▪ The JavaScript for of statement loops through the
values of an iterable object.
for (variable of iterable) {
// code block to be executed
}
▪ variable - For every iteration the value of the next property is assigned
to the variable. Variable can be declared with const, let, or var.
▪ iterable - An object that has iterable properties.
THE WHILE LOOP
▪ The while loop loops through a block of code as long as a specified
condition is true.
while (condition) {
// code block to be executed
}
THE DO WHILE LOOP
▪ The do while loop is a variant of the while loop. This loop will execute the code
block once, before checking if the condition is true, then it will repeat the loop
as long as the condition is true.
do {
// code block to be executed
}
while (condition);
JAVASCRIPT SWITCH STATEMENT
▪ The switch statement is used to perform different actions based on
different conditions.
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
JS EVENTS
▪ An HTML event can be something the browser does, or
something a user does.
▪ Ex-
• An HTML web page has finished loading
• An HTML input field was changed
• An HTML button was clicked
Refernce
https://www.w3schools.com/jsref/dom_obj_event.asp
JAVASCRIPT CLASSES
▪ Use the keyword class to create a class.
▪ Always add a method named constructor():
▪ A JavaScript class is not an object.
▪ It is a template for JavaScript objects.
class ClassName {
constructor() { ... }
}
Refernce
https://www.w3schools.com/js/js_classes.asp

More Related Content

PDF
PPTX
Javascript conditional statements
PPTX
Lab #2: Introduction to Javascript
PPSX
Javascript variables and datatypes
PDF
Basics of JavaScript
PPTX
Javascript
PPT
Introduction to Javascript
PPT
JavaScript - An Introduction
Javascript conditional statements
Lab #2: Introduction to Javascript
Javascript variables and datatypes
Basics of JavaScript
Javascript
Introduction to Javascript
JavaScript - An Introduction

What's hot (20)

PPTX
PPTX
Java script
PDF
JavaScript Programming
PPTX
Java script
PPT
Java Script ppt
PPTX
JavaScript Conditional Statements
PDF
Asynchronous JavaScript Programming
PDF
Javascript basics
PDF
Intro to Asynchronous Javascript
PDF
JavaScript - Chapter 5 - Operators
PPT
Javascript
PDF
JavaScript - Chapter 15 - Debugging Techniques
PDF
JavaScript - Chapter 11 - Events
PPSX
Introduction to Java
PDF
Bootstrap 5 basic
PPTX
Introduction to Spring Boot
PPT
Javascript
PDF
JavaScript - Chapter 8 - Objects
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PDF
Nodejs presentation
Java script
JavaScript Programming
Java script
Java Script ppt
JavaScript Conditional Statements
Asynchronous JavaScript Programming
Javascript basics
Intro to Asynchronous Javascript
JavaScript - Chapter 5 - Operators
Javascript
JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 11 - Events
Introduction to Java
Bootstrap 5 basic
Introduction to Spring Boot
Javascript
JavaScript - Chapter 8 - Objects
JavaScript - Chapter 13 - Browser Object Model(BOM)
Nodejs presentation
Ad

Similar to JavaScript Basics (20)

PPSX
JavaScript Comprehensive Overview
PPTX
Java script
PDF
JavaScript Looping Statements
PPTX
Lecture 4- Javascript Function presentation
PPTX
Introduction to JavaScript - Web Programming
PDF
JavaScript Basics and Best Practices - CC FE & UX
PPT
Web development basics (Part-4)
PPTX
Java script.pptx v
PPT
Javascript sivasoft
PDF
Javascript for Intermediates
PPTX
Learn To Code: Introduction to java
PPTX
js.pptx
PDF
WEB MODULE 3.pdf
PPTX
BITM3730 10-3.pptx
PPTX
BITM3730 10-4.pptx
PDF
Unit 4(it workshop)
PPTX
IP Unit 2.pptx
PDF
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
PPTX
gdscWorkShopJavascriptintroductions.pptx
JavaScript Comprehensive Overview
Java script
JavaScript Looping Statements
Lecture 4- Javascript Function presentation
Introduction to JavaScript - Web Programming
JavaScript Basics and Best Practices - CC FE & UX
Web development basics (Part-4)
Java script.pptx v
Javascript sivasoft
Javascript for Intermediates
Learn To Code: Introduction to java
js.pptx
WEB MODULE 3.pdf
BITM3730 10-3.pptx
BITM3730 10-4.pptx
Unit 4(it workshop)
IP Unit 2.pptx
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
gdscWorkShopJavascriptintroductions.pptx
Ad

Recently uploaded (20)

PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
master seminar digital applications in india
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Cardiovascular Pharmacology for pharmacy students.pptx
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Pharma ospi slides which help in ospi learning
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Open folder Downloads.pdf yes yes ges yes
PPH.pptx obstetrics and gynecology in nursing
Week 4 Term 3 Study Techniques revisited.pptx
human mycosis Human fungal infections are called human mycosis..pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O7-L3 Supply Chain Operations - ICLT Program
master seminar digital applications in india
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
Abdominal Access Techniques with Prof. Dr. R K Mishra
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Renaissance Architecture: A Journey from Faith to Humanism
TR - Agricultural Crops Production NC III.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF

JavaScript Basics

  • 2. PLAN 1. Intro to JS 2. JavaScript Integration with a html page 3. Js Variables 4. Js Operators 5. Js Functions 6. Loops 7. Switch 8. Js Events 9. Js Classes
  • 3. WHY STUDY JAVASCRIPT? JavaScript is one of the 3 languages all web developers must learn: 1. HTML to define the content of web pages 2. CSS to specify the layout of web pages 3. JavaScript to program the behavior of web pages
  • 5. INTRODUCTION ▪ JavaScript was designed to add interactivity to HTML pages ▪ JavaScript is a scripting language - a scripting language is a lightweight programming language ▪ JavaScript is an interpreted language (means that scripts execute without preliminary compilation) ▪ JavaScript is supported by all major browsers ▪ The language is dynamically typed ▪ No need to declare the type of a variable ▪ The type of a variable can change over time
  • 6. JAVASCRIPT INTEGRATION WITH A HTML PAGE 1. Inside the HTML File 2. As a external File
  • 7. Inside Html File ▪ We can put js inside a script tag ▪ It can included in head or body of the file External Js file • It separates HTML and code • It makes HTML and JavaScript easier to read and maintain • Cached JavaScript files can speed up page loads • Use script tag and src attribute
  • 8. HOW TO RUN JS ▪ Using browser developer tools(testing purpose only) ▪ Using html page
  • 9. JS VARIABLES Using var ▪ Variables defined with var can be Redeclared. ▪ Variables defined with var can be Declared after use. ▪ Variables defined with var do not have a Block Scope. Using let ▪ Variables defined with let cannot be Redeclared. ▪ Variables defined with let must be Declared before use. ▪ Variables defined with let have Block Scope.
  • 10. const ▪ Variables defined with const cannot be Redeclared. ▪ Variables defined with const cannot be Reassigned. ▪ Variables defined with const have Block Scope.
  • 12. FUNCTIONS ▪ A JavaScript function is a block of code designed to perform a particular task. ▪ A JavaScript function is executed when "something" invokes it (calls it). • When an event occurs (when a user clicks a button) • When it is invoked (called) from JavaScript code • Automatically (self invoked) function name(parameter1, parameter2, parameter3) { // code to be executed }
  • 13. LOOPS •for - loops through a block of code a number of times •for/in - loops through the properties of an object •for/of - loops through the values of an iterable object •while - loops through a block of code while a specified condition is true •do/while - also loops through a block of code while a specified condition is true
  • 14. THE FOR LOOP for (statement 1; statement 2; statement 3) { // code block to be executed } ▪ Statement 1 is executed (one time) before the execution of the code block. ▪ Statement 2 defines the condition for executing the code block. ▪ Statement 3 is executed (every time) after the code block has been executed.
  • 15. THE FOR IN LOOP for (key in object) { // code block to be executed } ▪ Loops over properties of a object
  • 16. THE FOR OF LOOP ▪ The JavaScript for of statement loops through the values of an iterable object. for (variable of iterable) { // code block to be executed } ▪ variable - For every iteration the value of the next property is assigned to the variable. Variable can be declared with const, let, or var. ▪ iterable - An object that has iterable properties.
  • 17. THE WHILE LOOP ▪ The while loop loops through a block of code as long as a specified condition is true. while (condition) { // code block to be executed } THE DO WHILE LOOP ▪ The do while loop is a variant of the while loop. This loop will execute the code block once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. do { // code block to be executed } while (condition);
  • 18. JAVASCRIPT SWITCH STATEMENT ▪ The switch statement is used to perform different actions based on different conditions. switch(expression) { case x: // code block break; case y: // code block break; default: // code block }
  • 19. JS EVENTS ▪ An HTML event can be something the browser does, or something a user does. ▪ Ex- • An HTML web page has finished loading • An HTML input field was changed • An HTML button was clicked Refernce https://www.w3schools.com/jsref/dom_obj_event.asp
  • 20. JAVASCRIPT CLASSES ▪ Use the keyword class to create a class. ▪ Always add a method named constructor(): ▪ A JavaScript class is not an object. ▪ It is a template for JavaScript objects. class ClassName { constructor() { ... } } Refernce https://www.w3schools.com/js/js_classes.asp