



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




High-level, interpreted programming languages like JavaScript are frequently employed to build dynamic, interactive webpages. Brendan Eich created it in 1995, and it has since grown to be one of the most widely used languages for online development. JavaScript is a full-fledged programming language that allows developers to add interaction and functionality to online pages, in contrast to HTML and CSS, which are markup languages used to structure and style web content. You can make API queries, manage user events, calculate, manipulate data, design responsive user interfaces, and much more with JavaScript. This cheat sheet provides an overview of essential JavaScript concepts and syntax.
โ Declaring variables: let variableName; - declares a variable that can be reassigned. const constantName; - declares a variable with a constant value (read- only). โ Assigning values: variableName = value; - assigns a value to a variable. โ Variable types: JavaScript has dynamic typing, meaning variables can hold different types of values such as numbers, strings, booleans, objects, arrays, null, and undefined.
โ Number: Represents numeric values, including integers and floating-point numbers. โ String : Represents textual data enclosed in single or double quotes โ Boolean: Represents the logical values true or false. โ Object : Represents a collection of key-value pairs and can contain functions, variables, and other objects. โ Array: Represents an ordered list of values and can store multiple values of any type โ Null: Represents the intentional absence of any object value. โ Undefined : Represents an uninitialized variable or missing property.
Perform mathematical operations on numbers. + (addition) , - (subtraction), * (multiplication), / (division), % (modulus). โ Assignment: Assign values to variables. = (assignment), += (addition assignment), -= (subtraction assignment), *= (multiplication assignment), /= (division assignment). โ Comparison: Compare values and return a Boolean result. == (equality), === (strict equality), != (inequality), !== (strict inequality), > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to).
โ Arrow functions: (parameters) => { ... } - provides a concise syntax for writing functions.
โ Object literals: Create objects using curly braces and key-value pairs: { key: value, ... }. โ Accessing properties: Access object properties using dot notation or square brackets: objectName.propertyName or objectName['propertyName']. โ Adding properties: Add new properties to an existing object: objectName.newProperty = value. โ Methods: Functions defined inside objects are called methods.
โ Creating arrays : Arrays store multiple values of any type in an ordered list: let arrayName = [element1, element2, ...]. โ Accessing elements: Access elements by their index (0-based): arrayName[index]. โ Array methods: Arrays have built-in methods to perform various operations like adding, removing, or transforming elements. Common methods include push(), pop(), shift(), unshift(), splice(), slice(), forEach(), map(), and filter().
โ Accessing elements: document.getElementById('id') - retrieves an element by its unique id. document.querySelector('selector') - retrieves the first element matching the CSS selector. โ Modifying elements : element.innerHTML = 'new content' - modifies the HTML content of an element. element.style.property = 'value' - modifies the CSS properties of an element. โ Event handling: Attach event listeners to elements using element.addEventListener('event', callback).
โ Try-Catch block: Use try { ... } catch (error) { ... } to handle exceptions and errors gracefully.