← Back to Hub

📋 Quick Reference Cheat Sheet

Fast lookup for common syntax across all languages

JavaScript
Python
C++
HTML
CSS

Variables

let name = "John"; // Can change const age = 25; // Cannot change var old = "avoid"; // Old way

Arrays

arr.push(4); // Add to end arr.pop(); // Remove from end arr.map(x => x * 2); // Transform all arr.filter(x => x > 5); // Keep matching

Functions

function greet(name) { return `Hello ${name}`; } const greet = (name) => `Hello ${name}`;

DOM

document.querySelector('.class'); el.textContent = "text"; el.classList.toggle('active');

Variables & Types

name = "John" # String age = 25 # Integer height = 5.9 # Float is_student = True # Boolean # Type conversion num = int("25") text = str(123)

Input/Output

print("Hello", name) name = input("Enter name: ") age = int(input("Enter age: ")) # F-strings print(f"I'm {age} years old")

Lists

lst = [1, 2, 3] lst.append(4) # Add to end lst.remove(2) # Remove value lst[0] # Access element lst[1:3] # Slice # List comprehension squares = [x**2 for x in range(5)]

Dictionaries

person = {"name": "John", "age": 25} person["name"] # Access value person["city"] = "NYC" # Add key-value person.keys() # All keys person.values() # All values

Control Flow

if age >= 18: print("Adult") elif age >= 13: print("Teen") else: print("Child") # Ternary status = "Pass" if score >= 60 else "Fail"

Loops

for i in range(5): # 0 to 4 print(i) for item in list: print(item) while count < 10: count += 1

Functions

def greet(name): return f"Hello {name}" # Lambda square = lambda x: x ** 2 print(square(5)) # 25

File Handling

# Read file with open("file.txt", "r") as f: content = f.read() # Write file with open("file.txt", "w") as f: f.write("Hello")

Basic Structure

#include <iostream> using namespace std; int main() { cout << "Hello" << endl; return 0; }

Variables & Types

int age = 25; float price = 9.99f; double pi = 3.14159; char grade = 'A'; string name = "John"; bool isTrue = true;

Input/Output

cout << "Hello " << name << endl; int age; cin >> age; string fullName; getline(cin, fullName);

Arrays & Vectors

// Array (fixed size) int arr[5] = {1, 2, 3, 4, 5}; arr[0] = 10; // Vector (dynamic) #include <vector> vector<int> vec = {1, 2, 3}; vec.push_back(4); vec.pop_back();

Control Flow

if (age >= 18) { cout << "Adult"; } else if (age >= 13) { cout << "Teen"; } else { cout << "Child"; } // Ternary string status = (age >= 18) ? "Adult" : "Minor";

Loops

for (int i = 0; i < 5; i++) { cout << i; } while (count < 10) { count++; } do { count--; } while (count > 0);

Functions

int add(int a, int b) { return a + b; } void greet(string name) { cout << "Hello " << name; } int main() { int sum = add(5, 3); greet("John"); }

Strings

#include <string> string text = "Hello"; text += " World"; text.length(); text.substr(0, 5); text.find("lo"); // Returns index text.replace(0, 5, "Hi");

Structure

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>Heading</h1> <p>Paragraph</p> </body> </html>

Common Tags

<a href="url">Link</a> <img src="img.jpg" alt="desc"> <button>Click</button> <input type="text"> <div>Block</div> <span>Inline</span>

Selectors

element { } .class { } #id { } element.class { } element > child { }

Flexbox

display: flex; justify-content: center; align-items: center; gap: 10px; flex: 1;