Java Script
It is used to create client-side dynamic pages. Java Script is an object-based scripting language that is lightweight and cross-platform.JavaScript is not a compiled language but it is a translated language. The javascript translator is responsible for translating the javascript code for the web browser
What is JavaScript?
Javascript is a lightweight object-oriented programming language which is used by several websites for scripting webpages. It is an interpreted, full-fledged programming language that enables dynamic interactivity on websites when applied to an HTML document. It 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 Couch DB and Mongo DB use JavaScript as their scripting and query language.
Feature of JavaScript
- All popular web browsers support Javascript as they provide built-in execution environments.
- It follows the syntax and structure of the C programming language. Thus, it is a structured programming language.
- It is a weakly typed language, where certain types are implicity cast.
- It is an object-oriented programming language, where it is also used as prototypes rather than using classes for inheritance.
- It is a lightweight and interpreted language.
- It is a case-sensitive language.
- It provides good control to the users over the web browsers.
History of JavaScript
In 1993, Mosaic, the first popular web browser, came into existence. In the year 1994, Netscape was founded by Marc Andreessen. He realized that we needed to become more dynamic. Thus a “glue language” was believed to be provided to HTML to make designing easy for designers and part-time programmers. Consequently, In 1995 the company recruited Brendan Eich intending to implement and embed scheme programming language to the web browser But before Brendan could start, the company merged with sun microsystems to add Java into its Navigators so that it could compete with Microsoft over the web technologies and platforms.
Application of JavaScript
JavaScript has numerous applications in various fields. Some of the main applications of JavaScript are as follows
- Dynamic drop-down menus.
- Displaying Date and Time.
- web developments.
- Server applications.
- presentations.
- Client-side Validation.
JavaScript Example
It is easy to code. Javascript provides 3 places to put the javascript code. Within the body tag, within the head tag, and external javascript file.
Example:-
<script type = “text/javascript”>
document.write(“javascript is a simple language”);
</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. We will learn about document objects in details later.
- Code between the body tag:- In the above example, we have displayed the dynamic content using JavaScript. Let’s see a simple example of JavaScript that displays an alert dialog box.
<script type = “text/javascript”>
alert (“Hello Javapoint”);
</script> - Code between the Head tag:- We are creating a function msg(). To create a function in javascript, you need to write a function with function_name as given below.
To call function, You need to work on an event. Here we are using the onclick event to call the msg() function.
<html/>
<head>
<script type = “text/javascript”>
function msg()
{
alert(“Hello JAvapoint”);
}
</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 an external javascript file and embed it in many HTML pages. It provides code reusability because a single javascript file can be used in several HTML pages. At 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.
message.js
function msg()
{
alert (“Hello java point”);
}
let’s include the javascript file into the HTML page. It calls the javascript function on button click.
index.HTML
<html>
<head>”
<script type = “text/javascript” STC = “message.js”></script>
</head>
<body>
<p> Welcome to javascript </p>
<form>
<input type = “button” value = “click” onclick = msg()”/>
</form>
</body>
</html>