SlideShare a Scribd company logo
Java Script
Overview of Java Script
• JavaScript (js) is a light-weight object-oriented programming
language which is used by several websites for scripting the
webpages.
• It is an interpreted, full-fledged programming language that
enables dynamic interactivity on websites when applied to an
HTML document.
• It was introduced in the year 1995 for adding programs to the
webpages in the Netscape Navigator browser.
• Since then, it has been adopted by all other graphical web
browsers. With JavaScript, users can build modern web
applications to interact directly without reloading the page
every time.
• The traditional website uses js to provide several forms of
interactivity and simplicity.
Continued...
• Although, JavaScript has no connectivity with Java
programming language.
• The name was suggested and provided in the times
when Java was gaining popularity in the market.
• In addition to web browsers, databases such as
CouchDB and MongoDB uses JavaScript as their
scripting and query language.
JavaScript Example
•Javascript example is easy to code.
•JavaScript provides 3 places to put the
JavaScript code:
1. Between the body tag of html
2. Between the head tag of html
3. In .js file (external javaScript)
Let’s create first JavaScript example
<script type="text/javascript">
document.write("JavaScript is a simple
language for javatpoint learners");
</script>
• The script tag specifies that we are using
JavaScript.
• The text/javascript is the content type that
provides information to the browser about the
data.
• The document.write() function is used to display
dynamic content through JavaScript.
1)Example : code between the body tag
• In the above example, we have displayed the
dynamic content using JavaScript.
• Let’s see the simple example of JavaScript that
displays alert dialog box.
<script type="text/javascript">
alert("Hello Javatpoint");
</script>
Introduction to JAVA SCRIPT USING HTML and CSS
2) Example : code between the
head tag
• Let’s see the same example of displaying alert dialog
box of JavaScript that is contained inside the head tag.
• In this example, we are creating a function msg().
• To create function in JavaScript, you need to write
function with function_name as given below.
• To call function, you need to work on event. Here we
are using onclick event to call msg() function.
Continued...
<html>
<head>
<script type="text/javascript">
function msg() {
alert("Hello Javatpoint"); }
</script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>
External JavaScript file
• We can create external JavaScript file and embed it in
many html page.
• It provides code re usability because single JavaScript file
can be used in several html pages.
• An external JavaScript file must be saved by .js extension.
• It is recommended to embed all JavaScript files into a
single file. It increases the speed of the webpage.
• Let's create an external JavaScript file that prints Hello
Javatpoint in a alert dialog box.
Continued...
message.js
function msg(){
alert("Hello Javatpoint");
}
 Let's include the JavaScript file into html page.
It calls the JavaScript function on button click.
Example
// index.html
<html>
<head>
<script type="text/javascript" src="message.js"></script>
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>
Introduction to JAVA SCRIPT USING HTML and CSS
Javascript Data Types
• JavaScript provides different data types to hold
different types of values.
• There are two types of data types in JavaScript.
1. Primitive data type
2. Non-primitive (reference) data type
Continued...
• JavaScript is a dynamic type language, means you don't
need to specify type of the variable because it is
dynamically used by JavaScript engine.
• You need to use var here to specify the data type.
• It can hold any type of values such as numbers, strings
etc.
• For example:
var a=40;//holding number
var b="Nakul";//holding string
JavaScript primitive data types
• String : represents sequence of characters
e.g. "hello"
• Number : represents numeric values
e.g. 100
• Boolean : represents boolean value either false
or true
• Undefined : represents undefined value
• Null : represents null i.e. no value at all
JavaScript non-primitive data
types
• The non-primitive data types are as follows:
• Object: represents instance through which
we can access members
• Array : represents group of similar values
• RegExp : represents regular expression
JavaScript Operators
• JavaScript operators are symbols that are used to
perform operations on operands.
• For example: var sum=10+20;
• Here, + is the arithmetic operator and = is the
assignment operator.
• Types of operators in JavaScript.
1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Bitwise Operators
4. Logical Operators
5. Assignment Operators
6. Special Operators
JavaScript Expressions
• JavaScript’s expression is a valid set of literals, variables,
operators, and expressions that evaluate a single value that
is an expression.
• This single value can be a number, a string, or a logical value
depending on the expression.
JavaScript Primary Expressions
Expressions Description
this keyword That defines the current line of code’s execution context
Async/Await Function Checks that we are not breaking the execution thread.
Object initializer
They have properties and methods attached to them and properties are in the
form of key-value pairs.
Grouping operator The Grouping operator consists of a pair of parentheses around an expression.
async function The async function is declared using the async keyword.
Regular Expressions The search pattern can be used for text search and text to replace operations.
function* Expression Define a generator function inside an expression
Function Expression Define a function inside an expression
class Expression The class name is used internally, but not outside of the class.

More Related Content

Similar to Introduction to JAVA SCRIPT USING HTML and CSS (20)

JavaScript_III.pptx
JavaScript_III.pptxJavaScript_III.pptx
JavaScript_III.pptx
rashmiisrani1
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptx
TusharTikia
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
PraveenKumar680401
 
Javascript
JavascriptJavascript
Javascript
Mozxai
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 
WTA-MODULE-4.pptx
WTA-MODULE-4.pptxWTA-MODULE-4.pptx
WTA-MODULE-4.pptx
ChayapathiAR
 
Java script202
Java script202Java script202
Java script202
Wasiq Zia
 
MTA understanding java script and coding essentials
MTA understanding java script and coding essentialsMTA understanding java script and coding essentials
MTA understanding java script and coding essentials
Dhairya Joshi
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
Syed Moosa Kaleem
 
concept of server-side JavaScript / JS Framework: NODEJS
concept of server-side JavaScript / JS Framework: NODEJSconcept of server-side JavaScript / JS Framework: NODEJS
concept of server-side JavaScript / JS Framework: NODEJS
Kongu Engineering College, Perundurai, Erode
 
Web Technology Part 2
Web Technology Part 2Web Technology Part 2
Web Technology Part 2
Thapar Institute
 
HNDIT1022 Week 08, 09 10 Theory web .pptx
HNDIT1022 Week 08, 09  10 Theory web .pptxHNDIT1022 Week 08, 09  10 Theory web .pptx
HNDIT1022 Week 08, 09 10 Theory web .pptx
IsuriUmayangana
 
Learning space presentation1 learn Java script
Learning space presentation1 learn Java scriptLearning space presentation1 learn Java script
Learning space presentation1 learn Java script
engmk83
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
Thinkful
 
Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017
Thinkful
 
Client sidescripting javascript
Client sidescripting javascriptClient sidescripting javascript
Client sidescripting javascript
Selvin Josy Bai Somu
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
AAFREEN SHAIKH
 
Presentation JavaScript Introduction Data Types Variables Control Structure
Presentation JavaScript Introduction  Data Types Variables Control StructurePresentation JavaScript Introduction  Data Types Variables Control Structure
Presentation JavaScript Introduction Data Types Variables Control Structure
SripathiRavi1
 
JavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptxJavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptx
rish15r890
 
WT Unit-3 PPT.pptx
WT Unit-3 PPT.pptxWT Unit-3 PPT.pptx
WT Unit-3 PPT.pptx
TusharTikia
 
Javascript
JavascriptJavascript
Javascript
Mozxai
 
Basics java scripts
Basics java scriptsBasics java scripts
Basics java scripts
ch samaram
 
Java script202
Java script202Java script202
Java script202
Wasiq Zia
 
MTA understanding java script and coding essentials
MTA understanding java script and coding essentialsMTA understanding java script and coding essentials
MTA understanding java script and coding essentials
Dhairya Joshi
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
Syed Moosa Kaleem
 
HNDIT1022 Week 08, 09 10 Theory web .pptx
HNDIT1022 Week 08, 09  10 Theory web .pptxHNDIT1022 Week 08, 09  10 Theory web .pptx
HNDIT1022 Week 08, 09 10 Theory web .pptx
IsuriUmayangana
 
Learning space presentation1 learn Java script
Learning space presentation1 learn Java scriptLearning space presentation1 learn Java script
Learning space presentation1 learn Java script
engmk83
 
Intro to javascript (6:19)
Intro to javascript (6:19)Intro to javascript (6:19)
Intro to javascript (6:19)
Thinkful
 
Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017Intro to JavaScript - Thinkful LA, June 2017
Intro to JavaScript - Thinkful LA, June 2017
Thinkful
 
Hsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdfHsc IT Chap 3. Advanced javascript-1.pdf
Hsc IT Chap 3. Advanced javascript-1.pdf
AAFREEN SHAIKH
 
Presentation JavaScript Introduction Data Types Variables Control Structure
Presentation JavaScript Introduction  Data Types Variables Control StructurePresentation JavaScript Introduction  Data Types Variables Control Structure
Presentation JavaScript Introduction Data Types Variables Control Structure
SripathiRavi1
 
JavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptxJavaScript New Tutorial Class XI and XII.pptx
JavaScript New Tutorial Class XI and XII.pptx
rish15r890
 

Recently uploaded (20)

প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
Pragya Champion's Chalice 2025 Set , General Quiz
Pragya Champion's Chalice 2025 Set , General QuizPragya Champion's Chalice 2025 Set , General Quiz
Pragya Champion's Chalice 2025 Set , General Quiz
Pragya - UEM Kolkata Quiz Club
 
K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910
PankajRodey1
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
Writing Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research CommunityWriting Research Papers: Guidance for Research Community
Writing Research Papers: Guidance for Research Community
Rishi Bankim Chandra Evening College, Naihati, North 24 Parganas, West Bengal, India
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdfপ্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
প্রত্যুৎপন্নমতিত্ব - Prottutponnomotittwa 2025.pdf
Pragya - UEM Kolkata Quiz Club
 
K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910K-Circle-Weekly-Quiz-May2025_12345678910
K-Circle-Weekly-Quiz-May2025_12345678910
PankajRodey1
 
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ..."Dictyoptera: The Order of Cockroaches and Mantises"  Or, more specifically: ...
"Dictyoptera: The Order of Cockroaches and Mantises" Or, more specifically: ...
Arshad Shaikh
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly WorkshopsLDMMIA Free Reiki Yoga S7 Weekly Workshops
LDMMIA Free Reiki Yoga S7 Weekly Workshops
LDM & Mia eStudios
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
Uterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managmentUterine Prolapse, causes type and classification,its managment
Uterine Prolapse, causes type and classification,its managment
Ritu480198
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based EducatorDiana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda - A Wauconda-Based Educator
Diana Enriquez Wauconda
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...
wygalkelceqg
 
Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..Cloud Computing ..PPT ( Faizan ALTAF )..
Cloud Computing ..PPT ( Faizan ALTAF )..
faizanaltaf231
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptxQUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
QUIZ-O-FORCE FINAL SET BY SUDIPTA & SUBHAM.pptx
Sourav Kr Podder
 
Ad

Introduction to JAVA SCRIPT USING HTML and CSS

  • 2. Overview of Java Script • JavaScript (js) is a light-weight object-oriented programming language which is used by several websites for scripting the webpages. • It is an interpreted, full-fledged programming language that enables dynamic interactivity on websites when applied to an HTML document. • It was introduced in the year 1995 for adding programs to the webpages in the Netscape Navigator browser. • Since then, it has been adopted by all other graphical web browsers. With JavaScript, users can build modern web applications to interact directly without reloading the page every time. • The traditional website uses js to provide several forms of interactivity and simplicity.
  • 3. Continued... • Although, JavaScript has no connectivity with Java programming language. • The name was suggested and provided in the times when Java was gaining popularity in the market. • In addition to web browsers, databases such as CouchDB and MongoDB uses JavaScript as their scripting and query language.
  • 4. JavaScript Example •Javascript example is easy to code. •JavaScript provides 3 places to put the JavaScript code: 1. Between the body tag of html 2. Between the head tag of html 3. In .js file (external javaScript)
  • 5. Let’s create first JavaScript example <script type="text/javascript"> document.write("JavaScript is a simple language for javatpoint learners"); </script> • The script tag specifies that we are using JavaScript. • The text/javascript is the content type that provides information to the browser about the data. • The document.write() function is used to display dynamic content through JavaScript.
  • 6. 1)Example : code between the body tag • In the above example, we have displayed the dynamic content using JavaScript. • Let’s see the simple example of JavaScript that displays alert dialog box. <script type="text/javascript"> alert("Hello Javatpoint"); </script>
  • 8. 2) Example : code between the head tag • Let’s see the same example of displaying alert dialog box of JavaScript that is contained inside the head tag. • In this example, we are creating a function msg(). • To create function in JavaScript, you need to write function with function_name as given below. • To call function, you need to work on event. Here we are using onclick event to call msg() function.
  • 9. Continued... <html> <head> <script type="text/javascript"> function msg() { alert("Hello Javatpoint"); } </script> </head> <body> <p>Welcome to JavaScript</p> <form> <input type="button" value="click" onclick="msg()"/> </form> </body> </html>
  • 10. External JavaScript file • We can create external JavaScript file and embed it in many html page. • It provides code re usability because single JavaScript file can be used in several html pages. • An external JavaScript file must be saved by .js extension. • It is recommended to embed all JavaScript files into a single file. It increases the speed of the webpage. • Let's create an external JavaScript file that prints Hello Javatpoint in a alert dialog box.
  • 11. Continued... message.js function msg(){ alert("Hello Javatpoint"); }  Let's include the JavaScript file into html page. It calls the JavaScript function on button click.
  • 12. Example // index.html <html> <head> <script type="text/javascript" src="message.js"></script> </head> <body> <p>Welcome to JavaScript</p> <form> <input type="button" value="click" onclick="msg()"/> </form> </body> </html>
  • 14. Javascript Data Types • JavaScript provides different data types to hold different types of values. • There are two types of data types in JavaScript. 1. Primitive data type 2. Non-primitive (reference) data type
  • 15. Continued... • JavaScript is a dynamic type language, means you don't need to specify type of the variable because it is dynamically used by JavaScript engine. • You need to use var here to specify the data type. • It can hold any type of values such as numbers, strings etc. • For example: var a=40;//holding number var b="Nakul";//holding string
  • 16. JavaScript primitive data types • String : represents sequence of characters e.g. "hello" • Number : represents numeric values e.g. 100 • Boolean : represents boolean value either false or true • Undefined : represents undefined value • Null : represents null i.e. no value at all
  • 17. JavaScript non-primitive data types • The non-primitive data types are as follows: • Object: represents instance through which we can access members • Array : represents group of similar values • RegExp : represents regular expression
  • 18. JavaScript Operators • JavaScript operators are symbols that are used to perform operations on operands. • For example: var sum=10+20; • Here, + is the arithmetic operator and = is the assignment operator. • Types of operators in JavaScript. 1. Arithmetic Operators 2. Comparison (Relational) Operators 3. Bitwise Operators 4. Logical Operators 5. Assignment Operators 6. Special Operators
  • 19. JavaScript Expressions • JavaScript’s expression is a valid set of literals, variables, operators, and expressions that evaluate a single value that is an expression. • This single value can be a number, a string, or a logical value depending on the expression.
  • 20. JavaScript Primary Expressions Expressions Description this keyword That defines the current line of code’s execution context Async/Await Function Checks that we are not breaking the execution thread. Object initializer They have properties and methods attached to them and properties are in the form of key-value pairs. Grouping operator The Grouping operator consists of a pair of parentheses around an expression. async function The async function is declared using the async keyword. Regular Expressions The search pattern can be used for text search and text to replace operations. function* Expression Define a generator function inside an expression Function Expression Define a function inside an expression class Expression The class name is used internally, but not outside of the class.