JavaScript

JavaScript is a high-level, interpreted programming language that is central to modern web development. It was created to enable interactive effects within web browsers, but is now used across web applications, mobile apps, and even back-end server environments.

JavaScript can be written and executed in different contexts, both in-browser and server-side. Its versatility and dynamic nature make it powerful for building rich user interfaces and real-time features, but also present unique security challenges when handling user input, data exchange, and cross-origin operations.

Some of its main components are:

  • Variables and Data Types: Fundamental storage units and the types of data they hold, such as strings, numbers, objects, and arrays

  • Functions: Blocks of reusable code that encapsulate logic and can be invoked with various arguments

  • Objects: Collections of related data and functions (methods), central to JavaScript’s flexible, object-oriented design

  • Events: Mechanisms that allow scripts to respond dynamically to user actions and system triggers (like clicks, keypresses, or form submissions)

  • DOM Manipulation: The capability to dynamically read and modify the structure and content of web pages via the Document Object Model (DOM)

  • Asynchronous Programming: Techniques like callbacks, promises, and async/await that allow non-blocking operations, enabling a responsive user experience.

These and others will be explored in detail in the section.

Primitive Data Types

Data types define the kind of value a variable will hold. JavaScript has a set of well-defined built-in data types, which are immutable basic values. Here we find some examples:

"hello", 'hello' // string, for textual data
3, 3.14 // number, for integers and floating-point
123456789012345678990n // bigint, for arbitrarily large integers
true, false // boolean, for logical values
undefined // Indicates a variable has been declared but not assigned a value
Symbol('id') // Symbol, for unique, collision-free identifiers 
null // Represents an empty value

Variables

Variables in JavaScript are containers used to store data values that can be referenced and manipulated in the code. They allow giving a name to a value to use it later, change it, or pass it to functions.

A variable gets declared (created) using the keywords var, let, or const. The difference between them is the scope in which they can be used and their mutability properties. In JavaScript, variables are dynamic, so they can hold any type of value, no matter what value they had before.

Variable names are case sensitive, can include letters, numbers, and the _ or $ characters, but can't start with a number or have the same name as keywords. To assign a value to a variable, the = character is used.

Here we find some examples:

Comments

The comments are notes in the code that are used for communication purposes and will not be considered in the execution.

There are two types of code comments in JavaScript:

  • A single-line comment, denoted with // preceding it


  • A multi-line comment, denoted with /* to begin the comment and */ to end it

Console

The console is a panel that displays/prints messages. It is a built-in tool present in web browsers and development environments that allows developers to view messages, errors, and warnings produced by JavaScript code running.

It also allows interaction directly with a web page’s JavaScript environment by typing commands, inspecting variables, and running code snippets in real time.

It is also considered an object with which we can interact. Here we find some examples:

Operators

The are various types of operators in JavaScript that let us manipulate values, make operations, access properties, check conditions, and even concatenate various types of them.

  • The arithmetic operators allow us to do mathematical calculations on numbers and manipulate string values


  • We also have special assignment operators that directly set a value after an operation


  • We also have comparison operators that let us perform logical checks between two values, and even concatenate various expressions


  • We also have a ternary operator that lets us establish logic when an expression is true and another when it's false


  • We also have a typeof operator that lets us know the data type of a variable

Last updated