Alex Chang

35 code snips · on codesnips 5 months

Front-end developer with 10+ years building modern web applications. Expert in responsive design, performance optimization, and accessibility. Passionate about creating...

javascript
// ES6 Class syntax
class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }

JavaScript classes and prototype-based inheritance

javascript classes oop
by Alex Chang 1 tab
javascript
// math.js - Named exports
export const PI = 3.14159;
export const E = 2.71828;

export function add(a, b) {
  return a + b;

JavaScript ES6 modules: import, export, and module patterns

javascript modules es6
by Alex Chang 1 tab
javascript
// Basic try-catch
try {
  const result = riskyOperation();
  console.log('Success:', result);
} catch (error) {
  console.error('Error occurred:', error.message);

Error handling and debugging techniques in JavaScript

javascript debugging error-handling
by Alex Chang 1 tab
javascript
// Basic GET request
fetch('https://api.example.com/users')
  .then(response => {
    console.log('Status:', response.status);
    console.log('OK:', response.ok);
    return response.json();

Fetch API for HTTP requests and AJAX communication

javascript fetch api
by Alex Chang 1 tab
javascript
// Creating elements
const div = document.createElement('div');
div.id = 'container';
div.className = 'box rounded';
div.textContent = 'Hello World';

DOM manipulation best practices and performance optimization

javascript dom manipulation
by Alex Chang 1 tab
javascript
// Basic event listener
const button = document.getElementById('myButton');

button.addEventListener('click', function(event) {
  console.log('Button clicked!');
  console.log('Event type:', event.type);

Event handling and event delegation patterns in JavaScript

javascript events event-delegation
by Alex Chang 1 tab
javascript
// Array destructuring
const numbers = [1, 2, 3, 4, 5];
const [first, second] = numbers;
console.log(first, second); // 1 2

// Skip elements

ES6+ features: destructuring, spread operator, and template literals

javascript es6 destructuring
by Alex Chang 1 tab
javascript
// Sample data
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const users = [
  { id: 1, name: 'Alice', age: 25, active: true },
  { id: 2, name: 'Bob', age: 30, active: false },
  { id: 3, name: 'Charlie', age: 35, active: true },

Array methods: map, filter, reduce, and functional programming

javascript arrays functional-programming
by Alex Chang 1 tab
javascript
// Creating a Promise
const myPromise = new Promise((resolve, reject) => {
  const success = true;

  setTimeout(() => {
    if (success) {

Promises and async/await patterns for asynchronous JavaScript

javascript promises async-await
by Alex Chang 1 tab
javascript
// Basic closure example
function outer() {
  const message = 'Hello from outer';

  function inner() {
    console.log(message); // Accesses outer variable

JavaScript closures and lexical scope fundamentals

javascript closures scope
by Alex Chang 1 tab
css
/* BEM - Block Element Modifier */

/* BLOCK - Independent component */
.card {
  padding: 1rem;
  border: 1px solid #ddd;

CSS architecture patterns: BEM and utility-first approaches

css architecture bem
by Alex Chang 2 tabs
css
/* Container Queries */
.card-container {
  container-type: inline-size; /* Creates query container */
  container-name: card;
}

Modern CSS features: container queries and :has() selector

css container-queries has-selector
by Alex Chang 1 tab