Introduction:

  1. JavaScript is a client side programming language.
  2. Which is used to create dynamic pages.
  3. It was developed by Netscape organization.
  4. It supports the features of OOPS.
  5. It is a case sensitive language.
  6. JS resides inside html document.
  7. No need to compile the JS code.
  8. JS code is run on browser only.
  9. JS file has file extension ".js".
  10. It is mainly used for
  11. Client side validations
  12. Displaying dynamic content.
  13. Displaying dialog boxes and pop up windows.
  14. Calculations.
  15. // is used for comments.
  16. ; is used for line termination.
  17. JS code must be inserted between <script> and </script> tags.
  18. We can write the code in the <head> or <body> section of html page.
  19. 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: