Kosal Ang
Sun Jan 07 2024
JavaScript is a versatile scripting language primarily used for client-side web development. It enables interactivity and dynamic content on web pages.
1console.log("Hello, JavaScript!"); // Outputs text to the browser console 2
JavaScript supports various data types like strings, numbers, booleans, arrays, and objects. Variables are declared using let
, const
, or var
.
1let name = "Kosal"; // String variable 2let age = 25; // Number variable 3const isStudent = true; // Boolean variable 4
JavaScript offers arithmetic, comparison, and logical operators to perform calculations and comparisons.
1let result = 10 + 5; // Addition operator 2let isEqual = 20 === 20; // Equality operator 3let isValid = (age >= 18) && (isStudent === false); // Logical AND operator 4
Control the flow of execution using if-else statements and loops.
1if (age >= 18) { 2 console.log("You are an adult."); 3} else { 4 console.log("You are a minor."); 5} 6 7for (let i = 0; i < 5; i++) { 8 console.log(`Count: ${i}`); 9} 10
Functions encapsulate blocks of code and can take parameters and return values.
1function greet(name) { 2 return `Hello, ${name}!`; 3} 4 5console.log(greet("Kosal")); // Outputs: Hello, Kosal! 6
JavaScript arrays and objects allow storing collections of data and key-value pairs.
1let numbers = [1, 2, 3, 4, 5]; // Array 2let person = { name: "Kosal", age: 25, isStudent: true }; // Object 3 4console.log(numbers[2]); // Accessing array element 5console.log(person.name); // Accessing object property 6
These examples illustrate foundational JavaScript concepts, demonstrating how variables, operators, control structures, functions, arrays, and objects are used within JavaScript code.
Creating a beautiful menu bar using HTML, CSS, and JavaScript involves creating the structure with HTML
JavaScript uses asynchronous programming. Promises and `async`/`await` are two powerful features that facilitate asynchronous operations in JavaScript
JavaScript's closures and scope are fundamental concepts that significantly impact how code behaves
If you're looking to build a responsive sidebar with icons and expandable menus, this HTML and CSS template can serve as a great starting point
Arrays and objects in JavaScript is fundamental for managing and manipulating data
ECMAScript 6, also known as ES6 or ECMAScript 2015, introduced several powerful features that significantly enhanced the capabilities of JavaScript
To get the Monday and Sunday of the week, use the setDate() method to set the day of the month of a date to the Monday and Sunday
Generate all permutations of string and filter unique string by using JavaScript
Dropdowns are a feature common to many websites. It's very useful, as they make it easy to show additional data only when it is needed.
TailwindCSS is a popular CSS framework that can help you create nice user interfaces quickly with pre-made CSS classes.