Introduction:
-
JavaScript is a client side programming language.
- Which is used to create dynamic pages.
- It was developed by Netscape organization.
- It supports the features of OOPS.
- It is a case sensitive language.
- JS resides inside html document.
- No need to compile the JS code.
- JS code is run on browser only.
- JS file has file extension ".js".
- It is mainly used for
- Client side validations
- Displaying dynamic content.
- Displaying dialog boxes and pop up windows.
- Calculations.
- // is used for comments.
- ; is used for line termination.
- JS code must be inserted between <script> and </script> tags.
- We can write the code in the <head> or <body> section of html page.
- We can write the separate .js file.
Syntax:
<script type="text/javascript">
document.write("javascript syntax");
</script>
Here document.write() is used to display dynamic content.
Example:
JS code in Html file:
(or)
Js code in Separate File:
Js code will be placed in separate .js extension file. To use that code, We have to mention the source file path in src attribute of script tag.
1) Datatypes:
JavaScript has 3 types of data,
- Numbers: 53,5.3
- Strings: "uma"
- Boolean: true / false.
2) Variables:
- Var is the keyword in JS to define variables.
- Variable can hold any type of value.
- Syntax: var var_name=value.
- EX: var name="uma", var rno="503"
- prompt is used to read the values.
Var vs Let:
- Both are used to define variables.
- Var is globally scoped.
- Let is locally scoped.
Example:
Output:
Task 1: Design a simple button on click of button display “hello javascript”.
Code: By using window.alert:


Output:

After clicking on button:

Code: By using document.write:

Output:
Code: By using window.alert:
Output:
After clicking on button:
Code: By using document.write:
Output: