Programming Language
JavaScript is a high-level, interpreted programming language that conforms to the ECMAScript specification. Created by Brendan Eich in 1995, it was originally designed as a scripting language for websites but has evolved into a fully-featured programming language used for both client and server-side development.
Despite its name, JavaScript has no direct relation to Java. It is a multi-paradigm language supporting object-oriented, imperative, and functional programming styles.
// Variable declarations let name = 'World'; // String variable with single quotes const age = 25; // Constant integer let pi = 3.14159; // Float variable let isActive = true; // Boolean variable // Template literals (ES6+) function helloWorld() { // Using template literals for string interpolation const message = `Hello, ${name}! You are ${age} years old.`; console.log(message); return isActive; } // Call the function and log result const result = helloWorld(); console.log(`The result is: ${result}`);
// Arrays - ordered collection const fruits = ['apple', 'banana', 'cherry']; fruits.push('orange'); // Add to the array // Objects - key-value pairs const person = { name: 'Alice', age: 30, isStudent: false, greet() { return `Hello, I'm ${this.name}`; } }; // Maps - key-value pairs with any type of key const userMap = new Map(); userMap.set('alice', { id: 1, role: 'admin' }); // Sets - collection of unique values const uniqueNumbers = new Set([1, 2, 3, 1, 4]); // Will contain {1, 2, 3, 4}
// Arrow functions (ES6+) const add = (a, b) => a + b; // Destructuring const { name, age } = person; // Spread operator const moreFruits = [...fruits, 'mango', 'pineapple']; // Async/await with Promises async function fetchData() { try { const response = await fetch('https://api.example.com/data'); const data = await response.json(); return data; } catch (error) { console.error('Error fetching data:', error); } }
JavaScript is one of the most versatile programming languages with a wide range of applications:
JavaScript has evolved significantly since its creation:
Modern JavaScript development often includes transpilation (with tools like Babel) to ensure compatibility with older browsers while using newer language features.
Here are some excellent resources for learning JavaScript:
Technologies often used with JavaScript or alternative options: