Skip to main content

Java Script

 Java Script Cheat Sheet

Here's a cheat sheet summarizing some of the common JavaScript concepts, functions, and syntax:

javascript
// JavaScript Cheat Sheet // Variables let variableName = value; // Declare a variable with block scope var variableName = value; // Declare a variable with function scope (deprecated) const constantName = value; // Declare a constant variable // Data Types let number = 10; // Number let string = "Hello"; // String let boolean = true; // Boolean let array = [1, 2, 3]; // Array let object = { // Object key1: value1, key2: value2 }; // Operators let sum = num1 + num2; // Addition let difference = num1 - num2; // Subtraction let product = num1 * num2; // Multiplication let quotient = num1 / num2; // Division let remainder = num1 % num2; // Modulus let isGreater = num1 > num2; // Greater than let isEqual = num1 === num2; // Equality let logicalAnd = condition1 && condition2; // Logical AND let logicalOr = condition1 || condition2; // Logical OR let logicalNot = !condition; // Logical NOT // Conditionals if (condition) { // Code executed if condition is true } else if (condition2) { // Code executed if condition2 is true } else { // Code executed if no previous conditions are true } // Loops for (let i = 0; i < limit; i++) { // Code executed in each iteration } while (condition) { // Code executed repeatedly while condition is true } do { // Code executed at least once, then repeatedly while condition is true } while (condition); // Functions function functionName(parameter1, parameter2) { // Code executed by the function return value; // Optional return statement } // Arrays let array = [1, 2, 3]; // Array declaration let length = array.length; // Length of the array let element = array[index]; // Accessing an element array.push(value); // Add an element to the end array.pop(); // Remove the last element array.unshift(value); // Add an element to the beginning array.shift(); // Remove the first element array.splice(index, count); // Remove or replace elements // Objects let object = { // Object declaration key1: value1, key2: value2, method: function() { // Method code } }; let value = object.key1; // Accessing a value object.key3 = value3; // Adding a new key-value pair delete object.key2; // Deleting a key-value pair // Events element.addEventListener('event', function() { // Code executed when the event occurs }); // DOM Manipulation let element = document.getElementById('id'); // Get element by ID let elements = document.getElementsByClassName('class'); // Get elements by class name let elements = document.getElementsByTagName('tag'); // Get elements by tag name element.innerHTML = 'Text'; // Set element's HTML content element.value = 'Value'; // Set element's value element.style.property = 'value'; // Set element's CSS style element.classList.add('class'); // Add a class to an element element.classList.remove('class'); // Remove a class from an element // Promises (Asynchronous) new Promise(function(resolve, reject) { // Asynchronous code if (success) { resolve(result); } else { reject(error); } }).then(function(result) { // Code executed on successful promise }).catch(function(error) { // Code executed on rejected promise }); // Fetch API (HTTP Requests) fetch(url) .then(function(response) { return response.json(); }) .then(function(data) { // Process the response data }) .catch(function(error) { // Handle errors }); // Modules (ES6) // Exporting module export const variableName = value; export function functionName() { // Code } // Importing module import { variableName, functionName } from './module.js';

This cheat sheet covers some of the commonly used JavaScript concepts, functions, syntax, conditionals, loops, arrays, objects, events, DOM manipulation, promises, Fetch API, and modules. It serves as a handy reference for quick look-ups and reminders while working with JavaScript.

Comments

Popular posts from this blog

Tokens, Identifiers, Data Types, Sequence Control, Subprogram Control, Arrays, Structures, Union, String, Pointers, Functions, File Handling, Command Line Argumaents, Preprocessors in C with example

 Let's discuss each concept briefly and provide examples for better understanding: 1. Tokens: Tokens are the smallest building blocks in C programming. They include keywords, identifiers, constants, strings, operators, and punctuators. Example: ```c #include <stdio.h> int main() {     int num = 42;  // 'int', 'main', 'return', '42', '=', ';' are tokens     printf("Hello, World!");  // 'printf', '(', ')', 'Hello, World!', ';', are tokens     return 0;  // 'return', '0', ';' are tokens } ``` 2. Identifiers: Identifiers are names used to identify variables, functions, or other user-defined entities. Example: ```c int age = 30;  // 'age' is an identifier (variable name) void displayMessage() {  // 'displayMessage' is an identifier (function name)     // function body } ``` 3. Data Types: Data types define the type of data that can be stored in ...

Web Programming: HTML, DHTML, XML, Scripting, Java, Servlets, Applets

 Web programming encompasses various technologies and concepts used to develop web applications. Let's explore each of them in detail: 1. HTML (Hypertext Markup Language): HTML is the standard markup language used to create the structure and content of web pages. It uses tags to define elements like headings, paragraphs, images, links, forms, etc. Example: ```html <!DOCTYPE html> <html> <head>     <title>My Web Page</title> </head> <body>     <h1>Hello, World!</h1>     <p>This is a paragraph.</p>     <img src="image.jpg" alt="Image">     <a href="https://www.example.com">Visit Example</a> </body> </html> ``` 2. DHTML (Dynamic HTML): DHTML is a combination of HTML, CSS, and JavaScript that allows web pages to become more dynamic and interactive. Example (DHTML with JavaScript): ```html <!DOCTYPE html> <htm...

Place holder and control character in c language

 In the C programming language, placeholders and control characters are used to format and control the output of text in console-based programs. They are special characters or sequences of characters that have specific meanings. Here are the placeholders and control characters commonly used in C: 1. Placeholders:    - %d: Used to display signed integers.      Example: printf("The value is %d", 10);    - %u: Used to display unsigned integers.      Example: printf("The value is %u", 10);    - %f: Used to display floating-point numbers.      Example: printf("The value is %f", 3.14);    - %c: Used to display characters.      Example: printf("The character is %c", 'A');    - %s: Used to display strings (sequence of characters).      Example: printf("The string is %s", "Hello");    - %p: Used to display memory addresses (pointers)...