0% found this document useful (0 votes)
13 views

Javascript 1

Uploaded by

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

Javascript 1

Uploaded by

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

CS4042D Web

Programming
JavaScript
Static and Dynamic Content
• Static - unchanged or constant
• Dynamic - changing or lively
Dynamic content
• Server-side scripting
• Client-side scripting
Static and Dynamic (Server-
side) Content
Client side Scripting
• Advantages
– Processing can be offloaded from the server
– The browser can respond more rapidly to user
events
• Disadvantages
– No guarantee that the client has enabled
client-side script
– Works in one browser may generate error in
another
– Decreases code readability
JavaScript
• Supports Client-side and Server-
side scripting
• JavaScript was introduced by
Netscape in their Navigator browser
back in 1996.
• It originally was called LiveScript
• Object oriented language
• Dynamically typed
• Any relation with Java?
What can JavaScript do?
Client-Side JavaScript
How all ways Client-Side JS
can be included in a Web
• Inline JS
Page?
<input type="button" onclick="alert('Are you sure?');" />
• Embedded JS
<script type="text/javascript">
/* A JavaScript Comment */
alert ("Hello World!");
</script>
• External JS
<head>
<script type="text/JavaScript" src="greeting.js">
</script>
</head>
Client-Side Javascript
<html>
<head>
<script>
function displayDate()
{
document.getElementById(“demo”).innerHTML=Date();
}
</script>
</head>
<body>
<h1>WELCOME TO JAVA SCRIPT</h1>
<p id=“demo”>to get current date click on display date.</p>
<button type=”button” onclick=“displayDate()”>Display Date</button>
</body>
</html>
Syntax
• Variables in JavaScript are
dynamically typed.

– New versions use let, const


• Operators
– Arithmetic
– Assignment
– Comparison
– Logical
Comparison Operators
Syntax
• Conditionals
var hourOfDay;
var greeting;
if (hourOfDay > 4 && hourOfDay < 12){
greeting = "Good Morning";
}
else if (hourOfDay >= 12 && hourOfDay < 20){
greeting = "Good Afternoon";
}
else{
greeting = "Good Evening";
}

• Loops
Things to note:
• Variables dynamically typed
• Auto semi-colon insertion
• === operator for comparison
• Block scope not supported
Demo
Exercise To Do:
• Write a JavaScript function that reverse a
number.
• Write a JavaScript function that accepts a string
as a parameter and converts the first letter of
each word of the string in upper case.
• Display pressed number in alert box.
Thank you

You might also like