19.4. Introduction to Javascript: variables, data types, operators: Operators in Javascript

Página 69

19.4. Introduction to Javascript: variables, data types, operators: Operators in Javascript

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

Javascript is a programming language that allows the creation of interactivity on web pages. It runs in the user's browser, which means that the code is processed on the user's computer and not on the server, as is the case with other programming languages. In this chapter, we will focus on operators in Javascript.

Operators in Javascript

Operators in Javascript are used to perform operations between variables and values. Operators are symbols that indicate an action to be performed. There are several types of operators in Javascript, including arithmetic operators, assignment operators, comparison operators, logical operators, and bitwise operators.

Arithmetic operators

Arithmetic operators are used to perform mathematical operations between numeric values. Arithmetic operators in Javascript include + (addition), - (subtraction), * (multiplication), / (division), % (modulus), ++ (increment), and -- (decrement).

Assignment operators

Assignment operators are used to assign values ​​to variables. The most common assignment operator is =, which assigns the value on the right of the operator to the variable on the left. Other assignment operators include +=, -=, *=, /=, and %=, which perform an arithmetic operation before assigning the result to the variable.

Comparison operators

Comparison operators are used to compare two values ​​and return a Boolean value that indicates whether the comparison is true or false. Comparison operators in Javascript include == (equal to), != (not equal to), > (greater than), < (less than), >= (greater than or equal to), <= (less than or equal to), === (equal to and of the same type) and !== (not equal to or not of the same type).

Logical operators

Logical operators are used to determine the logic between variables or values. Logical operators in Javascript include && (and), || (or) and ! (no).

Bitwise operators

Bitwise operators are used to manipulate the bits of a number. Bitwise operators in Javascript include & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NOT), << (left shift), >> (right shift) and >>> (right shift without signal).

Operators in Javascript are a fundamental part of the language and are used in almost all scripts. They allow programmers to perform complex operations with few lines of code. However, it is important to remember that operators must be used with caution, as inappropriate use can lead to unexpected results.

In summary, operators in Javascript allow programmers to perform a variety of operations, from simple mathematical calculations to complex comparisons and bit manipulations. Understanding how and when to use each type of operator is a fundamental skill for any Javascript programmer.

Now answer the exercise about the content:

What are the types of operators in Javascript mentioned in the text?

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

You missed! Try again.

Next page of the Free Ebook:

7020. Control structures in Javascript: if, for, while

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or 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