2. Introduction
1. JavaScript is a dynamic computer programming language.
2. 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.
3. JavaScript made its first appearance in Netscape 2.0 in 1995 with
the name LiveScript.
4. 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.
3. Advantages of JavaScript
1. 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.
2. Immediate feedback to the visitors: They don't have to wait for a
page reload to see if they have forgotten to enter something.
3. Increased interactivity: You can create interfaces that react when
the user hovers over them with a mouse or activates them via the
keyboard.
4. 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.
4. Limitations of JavaScript
We cannot treat JavaScript as a full-fledged programming language. It
lacks the following important features:
1. Client-side JavaScript does not allow the reading or writing of files.
This has been kept for security reason.
2. JavaScript cannot be used for networking applications because
there is no such support available.
3. JavaScript doesn't have any multithreading or multiprocessor
capabilities.
5. Types of JavaScript
1. Internal JavaScript
2. External JavaScript
1. Internal JavaScript: The internal JavaScript code can be written
inside the HTML document and it can be written in any section of
the HTML file (i.e. inside <HEAD> tag and <BODY> tag).
2. External JavaScript: A separate file is made and saved with
extension .js and this file is called inside the <HEAD> tag of HTML
file.
<script src=“filename.js” type=“text/javascript”></script>
6. Dialog Boxes in JavaScript
1. Prompt Box
2. Alert Box
3. Confirm Box
1. Prompt Box: This box is used to create input type dialog box.
prompt(“Enter Your Name ”, “like AKS”); à semicolon is unimportant
2. Alert Box: This box is used to create alert dialog box.
alert(“Your phone is about to blast”);
3. Confirm Box: This box is used to take action based on user
requirement. confirm(“Are you sure to clear all fields”);
7. Events in JavaScript
1. In JavaScript we use print statement
document.write(“Print Statement”); //print data
document.writeln(“Print Statement”); //print data and add new line
2. Onclick event : This event runs when we click any button type.
<input type=“submit” onclick=“confirm(‘Are you sure’)”>
<button type=“button” onclick=“alert(‘Thank you’)”>
3. Onmouseover and Onmouseout
<img src=“filename.png” onmouseover=“fun();” onmouseout=“funs();”>
4. ElementById : This is used to create and call the JavaScript id inside
HTML <BODY> tag.
document.getElementById(‘daa’).innerHTML=Date()
<p id=“daa”></p> It will give current date and time from your system.