0% found this document useful (0 votes)
31 views15 pages

Unit 3

Uploaded by

Abhinav Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views15 pages

Unit 3

Uploaded by

Abhinav Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Internet and Web Programming(CSE4001)

Dr. Kamlesh Chandravanshi


VIT, Bhopal
What is JavaScript

• JavaScript (js) is a light-weight object-oriented


programming language which is used by several websites
for scripting the web pages.
• 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 web pages in the Netscape Navigator browser.
Features of JavaScript

• All popular web browsers support JavaScript as they provide built-in


execution environments.
• JavaScript follows the syntax and structure of the C programming
language. Thus, it is a structured programming language.
• JavaScript is a weakly typed language, where certain types are
implicitly cast (depending on the operation).
• JavaScript is an object-oriented programming language that uses
prototypes rather than using classes for inheritance.
• It is a light-weighted and interpreted language.
• It is a case-sensitive language.
• JavaScript is supportable in several operating systems including,
Windows, macOS, etc.
• It provides good control to the users over the web browsers.
Application of JavaScript

• Client-side validation,
• Dynamic drop-down menus,
• Displaying date and time,
• Displaying pop-up windows and dialog boxes (like an
alert dialog box, confirm dialog box and prompt dialog
box),
• Displaying clocks etc.
<html>
<body>
<h2>Welcome to JavaScript</h2>
<script>
document.write("Hello JavaScript by JavaScript");
</script>
</body>
</html>
The document.write() function is used to display dynamic
content through JavaScript.
Places to put JavaScript code

• Between the body tag of html


• Between the head tag of html
• In .js file (external javaScript)
Advantages of External JavaScript

• There will be following benefits if a user creates an


external javascript:
– It helps in the reusability of code in more than one HTML file.
– It allows easy code readability.
– It is time-efficient as web browsers cache the external js files,
which further reduces the page loading time.
– It enables both web designers and coders to work with html
and js files parallelly and separately, i.e., without facing any
code conflictions.
– The length of the code reduces as only we need to specify the
location of the js file.
Disadvantages of External JavaScript

• There are the following disadvantages of external files:


– The stealer may download the coder's code using the url of the js
file.
– If two js files are dependent on one another, then a failure in one
file may affect the execution of the other dependent file.
– The web browser needs to make an additional http request to get
the js code.
– A tiny to a large change in the js code may cause unexpected
results in all its dependent files.
– We need to check each file that depends on the commonly created
external javascript file.
– If it is a few lines of code, then better to implement the internal
javascript code.
Javascript Data Types

• JavaScript provides different data types to


hold different types of values. There are two
types of data types in JavaScript.
– Primitive data type
– Non-primitive (reference) data type
primitive data types

Data Type Description


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
non-primitive data types

Data Type Description


Object represents instance through
which we can access members

Array represents group of similar values

RegExp represents regular expression


JavaScript Operators

• Arithmetic Operators
• Comparison (Relational) Operators
• Bitwise Operators
• Logical Operators
• Assignment Operators
• Special Operators
JavaScript If-else

• If Statement
• If else statement
• if else if statement
JavaScript Functions

• JavaScript functions are used to perform operations. We can


call JavaScript function many times to reuse the code.
• Advantage of JavaScript function
• There are mainly two advantages of JavaScript functions.
– Code reusability: We can call a function several times so it save
coding.
– Less coding: It makes our program compact. We don’t need to write
many lines of code each time to perform a common task.
JavaScript Function Syntax

function functionName([arg1, arg2, ...argN])


{
//code to be executed
}

You might also like