19. Introduction to JavaScript: Variables, Data Types, Operators

JavaScript is a dynamic programming language that is primarily used to add interactivity to web pages. It allows developers to manipulate web page elements and change their behavior according to user actions. In this chapter, we will explore the basic concepts of JavaScript, such as variables, data types, and operators.

Variables

Variables are used to store data that can be used and modified later in your code. In JavaScript, you can declare a variable using the 'var', 'let' or 'const' keyword. For example:


var name = 'John';
let age = 25;
const pi = 3.14;

Here, 'name' and 'age' are variables that store a string and a number, respectively. 'pi' is a constant that stores the value of pi. The main difference between 'var', 'let' and 'const' is scope and reassignment. 'var' has a function scope, while 'let' and 'const' have a block scope. Furthermore, 'const' does not allow reassignment of values.

Data Types

JavaScript has six primitive data types:

  • String: represents a sequence of characters. For example: 'Hello, World!'
  • Number: represents a numeric value. For example: 10, 3.14
  • Boolean: represents a true or false value.
  • Undefined: represents an undefined value.
  • Null: represents a null value.
  • Symbol: represents a unique value that is not equal to any other value.

In addition to these, JavaScript also has a data type called Object to store collections of data and more complex entities.

Operators

Operators are used to perform operations between variables and values. JavaScript has several types of operators:

  • Arithmetic operators: are used to perform mathematical operations. For example: +, -, *, /, %, ++, --
  • Assignment operators: are used to assign values ​​to variables. For example: =, +=, -=, *=, /=
  • Comparison operators: are used to compare two values. For example: ==, !=, ===, !==, >, <, >=, <=
  • Logical operators: are used to combine conditions. For example: &&, ||, !

These are the basic JavaScript concepts you need to understand to start programming in JavaScript. In the next chapter, we will explore more about functions and how they are used in JavaScript.

Now answer the exercise about the content:

_What is the main difference between 'var', 'let' and 'const' in JavaScript?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Introduction to Javascript: variables, data types, operators: Introduction to Javascript

Next page of the Free Ebook:

66Introduction to Javascript: variables, data types, operators: Introduction to Javascript

5 minutes

Obtenez votre certificat pour ce cours gratuitement ! en téléchargeant lapplication Cursa et en lisant lebook qui sy trouve. Disponible sur Google Play ou App Store !

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text