TutorialsJSCore JavaScript
Share:

Core JavaScript

intermediate

What You'll Learn

    Core JavaScript consists of the fundamental tools you need to write any program: operators to manipulate data, functions to organize logic, and control flow to direct execution.

    Operators perform actions on values. Arithmetic operators (+, -, *, /, %, **) handle math. Comparison operators (===, !==, >, <, >=, <=) compare values. Logical operators (&&, ||, !) combine boolean expressions. Assignment operators (=, +=, -=) update variables.

    Functions are reusable blocks of code. They can be declared with the function keyword, assigned to variables as expressions, or written as concise arrow functions (=>). Functions can accept parameters and return values — or return undefined if no return is specified.

    Control flow determines which code runs and how many times. Conditionals (if/else, switch, ternary ?:) make decisions. Loops (for, while, do...while) repeat operations. Methods like forEach, map, and filter iterate over arrays.

    Understanding these three pillars — operators, functions, and control flow — prepares you for any algorithmic challenge in JavaScript.

    Core JavaScript Concepts
    javascript

    Why this matters

    Operators, functions, and control flow are the building blocks of every JavaScript program. Mastering these fundamentals prepares you to solve any algorithmic challenge, whether you're building a calculator or a full web application.

    What's next

    In the next lessons, you'll dive deeper into each topic with hands-on examples and exercises.

    Exercises

    Operator and Function Practice

    easy

    Write a JavaScript function named calculate that takes three parameters: two numbers and an operator string ('+', '-', '*', '/'). Use a switch statement to perform the correct operation and return the result.

    Starter Code:

    function calculate(a, b, operator) {\n  // Your code here\n}\n\nconsole.log(calculate(10, 3, '+'));\nconsole.log(calculate(10, 3, '*'));

    Expected Output:

    13\n30

    Mini Quiz

    Mini Quiz