101.school
CoursesAbout
Search...⌘K
Generate a course with AI...

    JavaScript 101

    Receive aemail containing the next unit.
    • Introduction to JavaScript
      • 1.1What is JavaScript?
      • 1.2Setting up your environment
      • 1.3Basic syntax and variables
    • Data Types and Variables
      • 2.1Understanding data types
      • 2.2Variables and constants
      • 2.3Operators
    • Control Structures
      • 3.1Conditional statements
      • 3.2Loops
      • 3.3Error handling
    • Functions
      • 4.1Defining functions
      • 4.2Function expressions
      • 4.3Arrow functions
    • Objects and Arrays
      • 5.1Understanding objects
      • 5.2Understanding arrays
      • 5.3Array methods
    • Document Object Model (DOM)
      • 6.1What is the DOM?
      • 6.2Selecting and manipulating elements
      • 6.3Event handling
    • Asynchronous JavaScript
      • 7.1Callbacks
      • 7.2Promises
      • 7.3Async/Await
    • API Interaction
      • 8.1What is an API?
      • 8.2Fetch API
      • 8.3Working with JSON
    • Debugging
      • 9.1Console methods
      • 9.2Debugging tools
      • 9.3Common JavaScript errors
    • JavaScript Libraries
      • 10.1Introduction to libraries
      • 10.2Using jQuery
      • 10.3Using lodash
    • JavaScript Frameworks
      • 11.1Introduction to frameworks
      • 11.2Using React
      • 11.3Using Vue.js
    • Testing and Deployment
      • 12.1Writing tests with Jest
      • 12.2Deployment with Netlify
      • 12.3Continuous integration
    • Final Project
      • 13.1Project proposal
      • 13.2Project development
      • 13.3Project presentation

    Data Types and Variables

    Understanding Operators in JavaScript

    high-level programming language

    High-level programming language.

    Operators are the building blocks of any programming language. They allow us to perform operations on our data. In JavaScript, there are several types of operators: arithmetic, assignment, comparison, logical, and the ternary operator. This article will provide a comprehensive overview of each.

    Arithmetic Operators

    Arithmetic operators are used to perform mathematical operations:

    • Addition (+): Adds two numbers together.
    • Subtraction (-): Subtracts one number from another.
    • Multiplication (*): Multiplies two numbers together.
    • Division (/): Divides one number by another.
    • Modulus (%): Returns the remainder of a division operation.
    • Increment (++): Increases a number by 1.
    • Decrement (--): Decreases a number by 1.

    Assignment Operators

    Assignment operators are used to assign values to variables:

    • Equals (=): Assigns a value to a variable.
    • Plus equals (+=): Adds a value to a variable and assigns the result to that variable.
    • Minus equals (-=): Subtracts a value from a variable and assigns the result to that variable.
    • And so on for multiplication (*=), division (/=), and modulus (%=).

    Comparison Operators

    Comparison operators are used to compare two values:

    • Equals (==): Checks if two values are equal.
    • Not equals (!=): Checks if two values are not equal.
    • Greater than (>): Checks if one value is greater than another.
    • Less than (<): Checks if one value is less than another.
    • Greater than or equal to (>=): Checks if one value is greater than or equal to another.
    • Less than or equal to (<=): Checks if one value is less than or equal to another.
    • Strict equals (===): Checks if two values are equal in value and type.
    • Strict not equals (!==): Checks if two values are not equal in value or type.

    Logical Operators

    Logical operators are used to determine the logic between variables or values:

    • AND (&&): Returns true if both operands are true.
    • OR (||): Returns true if either operand is true.
    • NOT (!): Returns true if the operand is false, and false if the operand is true.

    Ternary Operator

    The ternary operator is a shorthand way of writing an if...else statement. It takes three operands: a condition, a value to return if the condition is true, and a value to return if the condition is false.

    condition ? valueIfTrue : valueIfFalse

    Operator Precedence and Associativity

    Operator precedence determines the order in which operations are performed when there are different operators in an expression. For example, multiplication and division have higher precedence than addition and subtraction.

    Associativity determines the order in which operations are performed when there are two or more operators of the same precedence in an expression. For example, assignment operators are right-associative, meaning they are evaluated from right to left.

    Understanding these operators is crucial to writing effective JavaScript code. They allow us to manipulate our data and control the flow of our programs.

    Test me
    Practical exercise
    Further reading

    Howdy, any questions I can help with?

    Sign in to chat
    Next up: Conditional statements