Introduction To JavaScript Programming
JavaScript is a versatile, high-level programming language mainly used to create interactive and dynamic web pages. It works with HTML and CSS to make websites more powerful, responsive, and user-friendly.
What is JavaScript?
JavaScript is one of the core technologies of the World Wide Web, along with HTML and CSS. It was created to make web pages alive by adding interactive features such as button clicks, form validation, animations, dynamic content updates, and real-time user responses.
Where is JavaScript Used?
Client-Side Browser
JavaScript runs inside browsers and helps build interactive web pages, forms, sliders, menus, popups, and live UI updates.
Server-Side
With Node.js, JavaScript can run on servers to create APIs, backend systems, and scalable applications.
Mobile Apps
Frameworks like React Native help developers create mobile applications using JavaScript.
Desktop Apps
Tools like Electron allow JavaScript to create desktop applications for Windows, macOS, and Linux.
CLOUD SERVICES
JavaScript is used in cloud-based applications, serverless computing, and real-time web services with platforms like Firebase and AWS.
GAME DEVELOPMENT
JavaScript helps developers create browser-based games, animations, and interactive gaming experiences using HTML5 Canvas and WebGL.
Basic Features of JavaScript
- Dynamic Typing: Variables can change data types.
- Object-Oriented: Supports object-oriented programming.
- Event-Driven: Handles clicks, forms, and keyboard events.
- Browser Support: Runs in all modern browsers.
JavaScript Variables
Variables store data values that can be reused throughout a program.
let name = "Rokeiya"; const age = 20; var city = "New York";
JavaScript Data Types
| Data Type | Description | Example |
|---|---|---|
| String | Text value | "Hello" |
| Number | Numeric value | 42 |
| Boolean | True or False | true |
| Array | Collection of values | [1,2,3] |
| Object | Key-value data | {name:"Rokeiya"} |
JavaScript Operators
Writing Your First JavaScript Program
<!DOCTYPE html> <html> <body> <script> document.write( "Hello PBA INSTITUTE!" ); </script> </body> </html>
User Input in JavaScript
JavaScript can take input from users using prompt(), confirm(), alert(), and HTML form fields.
let value =
prompt("Enter your name:");
alert(
"Welcome " + value
);
let ok =
confirm("Are you sure?");
Examples
<script> let a = 1; let b = 2; let c = 3; let d = 4; let e = a+b+c+d; document.write(e); </script>
<script> let length = 10; let breadth = 15; let area = length * breadth; document.write( "Area = " + area ); </script>
<script> let A = 15; let B = 25; let C; C = A; A = B; B = C; document.write( "A = " + A ); document.write( "<br>B = " + B ); </script>
B = 15
Conclusion
JavaScript is an important language for creating dynamic and interactive web applications. Understanding variables, data types, operators, and user input is the first step toward mastering JavaScript programming.