Hereโs a clear and concise definition of JavaScript:
๐ JavaScript
JavaScript is a high-level, interpreted, object-oriented programming language that is primarily used to create interactive and dynamic web pages. It is one of the core technologies of the World Wide Web, alongside HTML and CSS.
๐ง Key Characteristics:
- Client-side (runs in the browser) and server-side (via Node.js)
- Dynamically typed (no need to define data types)
-
Event-driven and asynchronous (e.g., with
setTimeout
,fetch
) - Prototype-based (supports OOP through prototypes and ES6 classes)
- Used to control the behavior of web elements like buttons, forms, animations, and real-time updates.
๐ Example:
<button onclick="greet()">Click Me</button>
<script>
function greet() {
alert("Hello, Sudhakar!");
}
</script>
โ In Short:
JavaScript is the language of the web, enabling developers to make websites dynamic, interactive, and user-friendly.
1. ๐ง Variables
Used to store data.
-
var
โ old, function-scoped -
let
โ block-scoped -
const
โ block-scoped, value can't be reassigned
let name = "Sudhakar";
const age = 25;
var isStudent = true;
2. ๐ข Data Types
- Primitive: Number, String, Boolean, Null, Undefined, Symbol
- Non-Primitive: Object, Array, Function
let num = 10; // Number
let str = "Hello"; // String
let isOk = true; // Boolean
let arr = [1, 2, 3]; // Array
let obj = {name: "SK"}; // Object
3. ๐งฎ Operators
Used to perform operations on variables and values.
let a = 5, b = 3;
console.log(a + b); // 8 (Arithmetic)
console.log(a > b); // true (Comparison)
console.log(a == b); // false
4. ๐ Control Statements
Control the flow of the program.
let age = 20;
if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}
for (let i = 1; i <= 3; i++) {
console.log(i); // 1, 2, 3
}
5. ๐ง Functions
Reusable blocks of code.
function greet(name) {
return "Hello " + name;
}
console.log(greet("Sudhakar"));
const add = (x, y) => x + y;
console.log(add(5, 3)); // 8
6. ๐ฆ Arrays and Objects
let colors = ["red", "green"];
console.log(colors[0]); // red
let person = {
name: "Sudhakar",
age: 25
};
console.log(person.name); // Sudhakar
7. ๐ฏ Events (in browser)
Used to handle user actions.
<button onclick="sayHi()">Click Me</button>
<script>
function sayHi() {
alert("Hello, Sudhakar!");
}
</script>
8. ๐น๏ธ DOM Manipulation
Used to change HTML/CSS with JavaScript.
<p id="demo">Old text</p>
<button onclick="changeText()">Change</button>
<script>
function changeText() {
document.getElementById("demo").innerHTML = "New text!";
}
</script>
9. ๐ค JavaScript in Web Development
- Runs in the browser
- Used for form validation, animations, fetching APIs, etc.
fetch("https://api.example.com/data")
.then(res => res.json())
.then(data => console.log(data));
Top comments (0)