Showing content from https://www.geeksforgeeks.org/introduction-to-javascript below:
Introduction to JavaScript - GeeksforGeeks
Introduction to JavaScript
Last Updated : 29 Jul, 2025
JavaScript is a versatile, dynamically typed programming language that brings life to web pages by making them interactive. It is used for building interactive web applications, supports both client-side and server-side development, and integrates seamlessly with HTML, CSS, and a rich standard library.
Javascript
- JavaScript is a single-threaded language that executes one task at a time.
- It is an interpreted language which means it executes the code line by line.
- The data type of the variable is decided at run-time in JavaScript, which is why it is called dynamically typed.
"Hello, World!" Program in Browser Console
A "Hello, World!" program is the simplest way to get started with any programming language. Here’s how you can write one using JavaScript.
HTML
<html>
<head></head>
<body>
<h1>Check the console for the message!</h1>
<script>
// This is our first JavaScript program
console.log("Hello, World!");
</script>
</body>
</html>
In this example
- The<script> tag is used to include JavaScript code inside an HTML document.
- console.log() prints messages to the browser's developer console. Open the browser console to see the "Hello, World!" message.
"Hello World" Program in Server Console
We can also print the "Hello World" program directly into the console terminal without embedded it into HTML. Create an index.js file and add the code to it.
JavaScript
// This is a comment
console.log("Hello, World!");
Run it in your terminal with:
node hello.js
Output:
Hello, World!
Comments are notes in your code that the JavaScript interpreter ignores. They’re great for explaining what your code does or for testing purposes.
- Single-line comment: Starts with //
C++
// This is a single-line comment
- Multi-line comment: Enclosed in /* */
C++
/* This is a multi-line comment
spanning multiple lines */
Key Features of JavaScript
Here are some key features of JavaScript that make it a powerful language for web development:
- Client-Side Scripting:JavaScript runs on the user's browser, so has a faster response time without needing to communicate with the server.
- Versatile: JavaScript can be used for a wide range of tasks, from simple calculations to complex server-side applications.
- Event-Driven: JavaScript can respond to user actions (clicks, keystrokes) in real-time.
- Asynchronous: JavaScript can handle tasks like fetching data from servers without freezing the user interface.
- Rich Ecosystem: There are numerous libraries and frameworks built on JavaScript, such as React, Angular, and Vue.js, which make development faster and more efficient.
Client Side and Server Side nature of JavaScript client side and server side
JavaScript's flexibility extends to both the client-side and server-side, allowing developers to create complete web applications. Here’s how it functions in each environment:
Client-Side:
- Involves controlling the browser and its DOM (Document Object Model).
- Handles user events like clicks and form inputs.
- Common libraries include AngularJS, ReactJS, and VueJS.
Server-Side:
- Involves interacting with databases, manipulating files, and generating responses.
- Node.js and frameworks like Express.js are widely used for server-side JavaScript, enabling full-stack development.
Programming Paradigms in JavaScript
JavaScript supports both imperative and declarative programming styles:
- Imperative Programming: Focuses on how to perform tasks by controlling the flow of computation. This includes approaches like procedural and object-oriented programming, often using constructs like async/await to handle asynchronous actions.
- Declarative Programming: Focuses on what should be done rather than how it’s done. It emphasizes describing the desired result, such as with arrow functions, without detailing the steps to achieve it.
Limitations of JavaScript
Despite its power, JavaScript has some limitations to consider:
- Security Risks : JavaScript can be used for attacks like Cross-Site Scripting (XSS), where malicious scripts are injected into a website to steal data by exploiting elements like <img>, <object>, or <script> tags.
- Performance : JavaScript is slower than traditional languages for complex tasks, but for simple tasks in a browser, performance is usually not a major issue.
- Complexity : To write advanced JavaScript, programmers need to understand core programming concepts, objects, and both client- and server-side scripting, which can be challenging.
- Weak Error Handling and Type Checking : JavaScript is weakly typed, meaning variables don’t require explicit types. This can lead to issues as type checking is not strictly enforced.
JavaScript Versions
Let’s take a look at the different versions of ECMAScript, their release years, and the key features they introduced
Version
Year
Key Features
ES5
2009
strict mode, JSON, getters/setters
ES6
2015
let/const, classes, arrow functions
ES7-ES13
2016-2022
async/await, BigInt, optional chaining
ES14
2023
toSorted
, findLast
, static blocks
Note: Older versions of browsers do not support ES6.
Introduction of JavaScript First program - Hello Geeks
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4