Experiment 5: Q. 1 What Is Javascript? Ans

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Web Development Lab Roll no.

16EGCCS029

Experiment 5
Q. 1 What is JavaScript?

Ans. JavaScript is a dynamic computer programming language. It is lightweight and most commonly
used as a part of web pages, whose implementations allow client-side script to interact with the user and
make dynamic pages. It is an interpreted programming language with object-oriented capabilities.
JavaScript was first known as Live Script, but Netscape changed its name to JavaScript, possibly
because of the excitement being generated by Java. JavaScript made its first appearance in Netscape 2.0
in 1995 with the name Live Script. The general-purpose core of the language has been embedded in
Netscape, Internet Explorer, and other web browsers.
The ECMA-262 Specification defined a standard version of the core JavaScript language.
 JavaScript is a lightweight, interpreted programming language.
 Designed for creating network-centric applications.
 Complementary to and integrated with Java.
 Complementary to and integrated with HTML.
 Open and cross-platform

Advantages of JavaScript
The merits of using JavaScript are −
 Less server interaction − You can validate user input before sending the page off to the server.
This saves server traffic, which means less load on your server.
 Immediate feedback to the visitors − They don't have to wait for a page reload to see if they
have forgotten to enter something.
 Increased interactivity − You can create interfaces that react when the user hovers over them
with a mouse or activates them via the keyboard.
 Richer interfaces − You can use JavaScript to include such items as drag-and-drop components
and sliders to give a Rich Interface to your site visitors.

Q. 2 Print Hello, world! with the help of JavaScript.

Ans.

<!DOCTYPE HTML>
<html>
<body>
<script>
document.write( 'Hello, world!' );
</script>
</body>
</html>

Page|32
Web Development Lab Roll no. 16EGCCS029

Output:

Popup Button:

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function say_Hello()
{
alert("hi")
}
</script>
</head>
<body>
<script type="text/javascript">
document.write( "Hello" );
</script>
<input type="button" onclick="say_Hello()" value="click to print hi">
</body>
</html>
Output:

Q. 3 Operators in JavaScript.
Ans. JavaScript Arithmetic Operators
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Operators</h2>

<p>x = 5, y = 2, calculate z = x + y,d = x - y,e = x * y,f = x / y,g=++x,t=--x and display z,d,e,f:</p>

Page|33
Web Development Lab Roll no. 16EGCCS029

<script>
var x = 5;
var y = 2;
var z = x + y;
var d = x - y;
var e = x * y;
var f = x / y;
var g = ++x;
var t = --x;

document.write(z);
document.write("\n");
document.write(d);
document.write("\n");
document.write(e);
document.write("\n");
document.write(f);
document.write("\n");
document.write(g);
document.write("\n");
document.write(t);
</script>

</body>
</html>
Output:

JavaScript Logical Operators


<!DOCTYPE html>
<html>
<head>
<h1>operators in javascript</h1>
</head>
<body>
<script type="text/javascript">
var a=1;
var b=0;
document.write(1 || 0);

Page|34
Web Development Lab Roll no. 16EGCCS029

document.write("<br>");
document.write(1 && 0);
document.write("<br>");
document.write(~1);
document.write("<br>");
document.write(~0);
document.write("<br>");
document.write(1 ^ 0);
</script>
</body>
Output:

Q. 4 For loop in JavaScript.


Ans.
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript For Loop</h2>
<script>
var text = "";
var i;
for (i = 0; i < 5; i++) {
text += "The number is " + i + "<br>";
}
document.write(text);
</script>
</body>
</html>

Page|35

You might also like