💻 Programming

JavaScript

JS

The language of the web. Runs in browsers and Node.js. Dynamic typing, prototype-based object orientation.

📖 Detailed Explanation

JavaScript is a programming language created in just 10 days in 1995 by Brendan Eich at Netscape. Originally called Mocha, then LiveScript, it was eventually renamed JavaScript, and today it is the most widely used programming language, found on more than 98% of websites worldwide.

JavaScript was originally designed for simple dynamic effects in the browser, but the arrival of Node.js in 2009 extended its reach to the server side. This made full-stack development possible, and the npm ecosystem, with over 2 million packages, has become the world's largest open-source ecosystem.

JavaScript's key features are dynamic typing, first-class functions, prototype-based inheritance, and event-driven asynchronous programming. It runs on a single thread but handles asynchronous work efficiently through the event loop, delivering excellent performance on I/O-bound tasks.

In practice, JavaScript is used for everything from front-end frameworks such as React, Vue, and Angular to Node.js-based back ends and mobile/desktop app development with React Native or Electron. As of 2025 it is the most used language on GitHub, and in AI/ML, TensorFlow.js lets you run machine learning models directly in the browser.

💻 Code Example

// 1. 기본 문법과 비동기 처리
async function fetchUserData(userId) {
    try {
        const response = await fetch(`https://api.example.com/users/${userId}`);
        if (!response.ok) throw new Error('네트워크 응답 실패');
        const user = await response.json();
        console.log(`사용자: ${user.name}, 이메일: ${user.email}`);
        return user;
    } catch (error) {
        console.error('데이터 가져오기 실패:', error.message);
        throw error;
    }
}

// 2. 배열 메서드와 함수형 프로그래밍
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const result = numbers
    .filter(n => n % 2 === 0)      // 짝수만: [2, 4, 6, 8, 10]
    .map(n => n * n)               // 제곱: [4, 16, 36, 64, 100]
    .reduce((sum, n) => sum + n, 0); // 합계: 220

console.log(`짝수 제곱의 합: ${result}`);

// 3. 클래스와 모듈 패턴 (ES6+)
class EventEmitter {
    #listeners = new Map();

    on(event, callback) {
        if (!this.#listeners.has(event)) {
            this.#listeners.set(event, []);
        }
        this.#listeners.get(event).push(callback);
        return this;
    }

    emit(event, ...args) {
        const callbacks = this.#listeners.get(event) || [];
        callbacks.forEach(cb => cb(...args));
    }
}

// 사용 예시
const emitter = new EventEmitter();
emitter.on('data', (msg) => console.log('받은 메시지:', msg));
emitter.emit('data', '안녕하세요!'); // 출력: 받은 메시지: 안녕하세요!

🗣️ Say It Like This in Practice

💬 In a Meeting
"This feature needs server-side rendering, so it would be best to implement it with Next.js. Code splitting can also cut the JavaScript bundle size and bring the initial load down to under 200KB."
💬 In an Interview
"JavaScript's event loop consists of the call stack, the task queue, and the microtask queue. A Promise's then is handled as a microtask, so it runs before setTimeout. You need to understand this execution order to prevent asynchronous bugs."
💬 In a code review
"You're using async/await here, but there's no error handling. Please wrap it in try-catch or add a .catch() chain. In production, an unhandled rejection could crash the process."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

❌
Use === instead of ==

`==` performs type coercion, so `'5' == 5` is true. Always use `===` so that types are compared as well. Enabling ESLint's eqeqeq rule helps prevent mistakes.

❌
Closures and loop variables

If you use var in a for loop, the closure only references the last value. Use let, or use array methods such as forEach/map.

✅
Use modern JavaScript syntax

Making active use of ES6+ syntax such as const/let, arrow functions, destructuring, the spread operator, optional chaining (?.), and nullish coalescing (??) makes code more concise and safer.

🔗 Related Terms

📚 Learn More