Introduction

JavaScript is the most widely used programming language for web development. It allows you to create dynamic, interactive, and modern pages, both in the browser and on the server. In this course, you will learn the fundamental concepts of JavaScript from scratch, with clear explanations and practical examples in English. No prior experience is required—just the desire to learn and practice.

By the end, you will have the necessary foundation to create your own scripts, understand technical documentation, and move on to modern frameworks like React, Vue, or Node.js.

Let’s start this journey into the world of JavaScript together!

Basic Syntax

  • Variables:
    • Use let and const to declare variables.
    • let allows you to declare variables whose value can change throughout the program, while const is used for variables whose value should not change (constants).
    • Example:
      let name = 'John';
      const PI = 3.1416;
  • Data Types:
    • Numbers, strings, booleans, null, undefined, objects, and arrays.
      let number = 10; // number
      let text = 'Hello'; // string
      let isActive = true; // boolean
      let nothing = null; // null
      let undefinedValue; // undefined
      let object = { key: 'value' }; // object
      let list = [1, 2, 3]; // array
  • Arrays:
    • Ordered collection of elements.
    • Arrays are important because they allow you to store and manipulate multiple values in a single variable, making it easier to iterate, search, modify, or remove elements efficiently. Using arrays helps organize related data and simplifies handling lists in programs.
      let fruits = ['apple', 'banana', 'grape'];
      console.log(fruits[0]); // 'apple'
      fruits.push('orange');
  • Objects:
    • Structure for grouping data and functions under a single entity. Objects allow you to represent real-world entities using properties (keys and values) and methods (associated functions). Each property can be any data type, and methods define behaviors.
      let person = {
        name: 'Anna',
        age: 25,
        greet: function () {
          console.log('Hi, I am ' + this.name);
        },
      };
      person.greet();
      // Access properties
      console.log(person.name); // 'Anna'
      // Modify properties
      person.age = 26;
      // Add new properties
      person.profession = 'Developer';
  • Operators:
    • Arithmetic: +, -, *, /, %
    • Comparison: ==, ===, !=, !==, <, >, <=, >=
    • Logical: &&, ||, !
      let sum = 2 + 3; // 5
      let isEqual = 5 === '5'; // false
      let result = true && false; // false
  • Comments:
    • Single line: // comment
    • Multi-line:
      /*
        This is a
        multi-line comment
      */
  • Functions:
    • Allow you to group a block of code that can be reused and executed when needed.
    • Declaration:
      function greet() {
        console.log('Hello world');
      }
    • Arrow function:
      const add = (a, b) => a + b;
  • Conditionals:
    • Allow you to execute different blocks of code depending on whether a condition is met.
      if (age >= 18) {
        console.log('You are an adult');
      } else {
        console.log('You are a minor');
      }
  • Loops:
    • Allow you to execute a block of code multiple times in a repetitive way.

      for (let i = 0; i < 5; i++) {
        console.log(i);
      }
    • There are also other types of loops:

      • while:
        let counter = 0;
        while (counter < 5) {
          console.log(counter);
          counter++;
        }
      • do…while:
        let number = 0;
        do {
          console.log(number);
          number++;
        } while (number < 5);

Exercises

  1. Declare a variable called name and assign your name to it. Display the value in the console.
  2. Write a function that receives two numbers and returns their sum.
  3. Create a conditional that prints “Even” if a number is even and “Odd” if it is odd.
  4. Write a loop that prints the numbers from 1 to 10.
  5. Create an arrow function that multiplies two numbers and displays the result.