Free Ebook cover Complete HTML, CSS and Javascript course to become a Front End Developer

Complete HTML, CSS and Javascript course to become a Front End Developer

3.79

(14)

125 pages

Introduction to Javascript: variables, data types, operators

Capítulo 65

Estimated reading time: 3 minutes

Audio Icon

Listen in audio

0:00 / 0:00

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.

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

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.

The main difference between 'var', 'let', and 'const' in JavaScript is their scope and reassignment capabilities. 'var' has a function scope, while 'let' and 'const' have a block scope. Additionally, 'const' does not allow reassignment of values once they are declared.

Next chapter

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

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.