Introduction to Javascript Programming

JavaScript is a versatile, high-level programming language primarily used to create interactive and dynamic content on the web. Here's an overview to help you understand the basics:

  • What are JavaScript ?
  • JavaScript is a high-level, interpreted programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. It was initially created to "make web pages alive," meaning it allows for the addition of interactive and dynamic elements to websites.

  • Where is JavaScript used ?
  • JavaScript is used in a variety of environments:
    Client-Side (in Browsers) : JavaScript runs in the user's web browser, allowing for interactive web pages. Examples include form validation, dynamic content updates, and interactive graphics.
    Server-Side (with Node.js) : JavaScript can run on servers using environments like Node.js, enabling the creation of scalable and high-performance network applications.
    Mobile and Desktop Applications : Frameworks like React Native and Electron use JavaScript to build mobile and desktop applications.

  • Basic Features of JavaScript :
  • Dynamic Typing : Variables in JavaScript can hold any type of data and can change types dynamically.
    Object-Oriented : JavaScript supports object-oriented programming with prototypes rather than classes.
    Event-Driven : JavaScript is often used to handle events like user clicks, form submissions, and page loads.

  • Where does JavaScript run ?
  • JavaScript can be executed in web browsers (like Chrome, Firefox, Safari) and on servers (using environments like Node.js).

  • Javascript variables :
  • Variables store data that can be used and manipulated throughout your code.
    let name = "Rokeiya";
    const age = 20;
    var city = "New York";

  • Javascript data types :
  • JavaScript supports various data types such as:
    String : "Hello, World!"
    Number : 42
    Boolean : true or false
    Array : [1, 2, 3, 4, 5]
    Object : { name: "Rokeiya", age: 20 }
    Null : null
    Undefined : undefined

  • Javascript operators :
  • JavaScript includes arithmetic operators (+, -, *, /), comparison operators (==, ===, !=, !==, <, >, <=, >=), and logical operators (&&, ||, !).

  • writing your first javascript program
  • JavaScript code
    <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> document.write("Hello PBA INSTITUTE!"); </script> </body> </html>

    Output :
    Hello PBA INSTITUTE!

  • Examples :
  • JavaScript code
    # Write a program to print their sum on the screen. <!DOCTYPE html> <html> <script type="text/javascript"> a=1; b=2; c=3; d=4; e=a+b+c+d; document.write(e); </script> </html>

    Output :
    10

    JavaScript code
    # Write a program to find out the area of rectangle. Length=10cm, Breadth= 15cm. Area of a rectangle = length * breadth <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> L=10; B=15; A=L*B; document.write("Area of rectangle=",A) </script> </body> </html>

    Output :
    Area of rectangle=150

    JavaScript code
    # Write a program to interchange the values of variable with using third variable. A=15 B=25 Output : A=25 B=15 <!DOCTYPE html> <html> <head> <title></title> </head> <body> <script type="text/javascript"> var A=15; var B=25; c=A; A=B; B=c; document.write("A = "+A+"<br>") document.write("B = "+B+"<br>") </script> </body> </html>

    Output :
    A = 25
    B = 15

    JavaScript code
    # Write a program to interchange the values of variable without using third variable. <!DOCTYPE html> <html> <script type="text/javascript"> a=10; b=15; a=a+b; b=a-b; a=a-b; document.write("<b>A=</b>"+a+"<br>"); document.write("<b>B=</b>"+b); </script> </html>

    Output :
    A=15
    B=10

  • Conclusion
  • JavaScript is an essential language for web development, enabling developers to create dynamic and interactive web experiences. Understanding the basics of JavaScript, including its syntax, data types, control structures, and event handling, is the first step in becoming proficient in this powerful language. From here, You can explore more advanced topics to enhance your skills.