JavaScript: Operators. Arithmetic Operators in JavaScript

Mathematical operations are one of the most basic and universal functions of any kind of programming. In JavaScript, numbers are often featured in trivial tasks, such as the designation of a browser window, the calculation of the residual value of a penny transaction, or between the elements of a document site.

To be a good retailer, mothers of high school students in mathematics are not obov'yazkovo, prote for whom it is important to know, what types of JavaScript operations are available and how to master them for practical tasks.

For other types of programming, JavaScript can only have one numeric data type; vіn do not subdіlyає tsіlі numbers that numbers with a floating point.

This guide is about arithmetic operators, operators are assigned the order of operations with JavaScript numeric data.

Arithmetic Operators

Arithmetic operators are symbols that represent mathematical operations and rotate the result. For example, 3 + 7 = 10 symbol + indicates the syntax of the folding operation.

You know a lot of JavaScript operators from basic mathematics, but also some additional operators.

All JavaScript arithmetic operators are presented in the next table.

Operator Syntax Butt Appointment
Addition + x+y Amount x and y
Vidnimannya x-y Retail between x and y
Reproduction * x*y Let's go x and y
Podil / x/y Private x and y
Module % x % y Surplus x/y
Zvedennya in the foot ** x**y x at stage y
Increment ++ x++ x plus one
Decrement x- x minus one

Storage and visual

The folding operators are available in JavaScript and can be used to calculate the sum and difference of numeric values. JavaScript can run a calculator, and math operations can run through the console.

The plus sign allows you to add numbers, for example:

Cream of operations with prime numbers JavaScript allows you to add numbers to change and calculate them. For example, you can assign numerical values ​​to change x and y, and place the result in z.

// Assign values ​​to x and y
let x = 10;
let y = 20;
// Add x and y and assign the sum to z
let z = x + y;
console log(z);
30

// Assign values ​​to x and y
let x = 10;
let y = 20;
// Subtract x from y and assign the difference to z
let z = y - x;
console log(z);
10

// Assign values ​​to x and y
let x = -5.2;
let y = 2.5;
// Subtract y from x and assign the difference to z
let z = x - y;
console log(z);
-7.7

JavaScript has one peculiarity, like a trace to protect that nobility - the result of folding the number of that row. We know that 1 + 1 can be 2, otherwise you can see a mismatched result.

let x = 1 + "1";
console log(x);
typeofx;
11
"string"

Instead of folding numbers, JavaScript transforms all of them into rows and combines them. It is important to be careful about the dynamic typing of JavaScript, shards of it can cause bad results.

Folder and JavaScript are often used to scroll the navigation bar.

function scrollToId() (
const navHeight = 60;
window.scrollTo(0, window.pageYOffset - navHeight);
}
window.addEventListener("hashchange", scrollToId);

In this direction, the panel scrolls by 60 pixels per id.

Plural and rose

Multiplication operators and sub-JavaScript hacks for random and private numeric values.

Zirochka є multiplication operator.

// Assign values ​​to x and y
let x = 20;
let y = 5;
// Multiply x by y to get the product
let z = x * y;
console log(z);
100

The multiple can be vikoristovuvatime rozrahunku cіni goods pіslya introduction tax z sale.

const price = 26.5; // Price of item before tax
const taxRate = 0.082; // 8.2% tax rate
// Calculate total after tax to 2 decimal places
let totalPrice = price + (price *taxRate);
totalPrice.toFixed(2);
console.log("Total:", totalPrice);
Total: 28.67

Slish – sub-line operator.

// Assign values ​​to x and y
let x = 20;
let y = 5;
// Divide y into x to get the quotient
let z = x/y;
console log(z);
4

He gave a particularly corny at the time of the rose, for example, when calculating the number of years, or there were a hundred correct signs at the test.

The absolute value of a number

Module - one more arithmetic operator, less popular, lower in front. Filed with the % symbol. Vіn turn over the surplus when rozpodіli the first number on the other.

For example, we know that 9 is divided by 3 without too much:

The modulus of the number allows you to assign a pair or an unpaired number, for example:

// Initialize function for testing, so the number is even
const isEven = x => (
// If the remainder after dividing by two is 0, return true
if (x % 2 === 0) (
return true;
}
// If the number is odd, return false
return false;
}
// Test the number
isEven(12);
true

In my butt, 12 is divided by 2, the same number for the guy.

In programming, the number module is often victorious in combination with smart operators.

Zvedennya in the foot

Step into the Steps is one of the newest JavaScript operators. The syntax of the link to the rіven is two zirochki pospil (**).

For example, 10 at the fifth step (10 ^ 5) is written like this:

10 ** 5;
100000

Operation 10**5 may have the same result as 10*10, repeated 5 times.

10 * 10 * 10 * 10 * 10;

This operation can also be written using the Math.pow() method.

Math.pow(10, 5);
100000

The choice of the step operator at the steps is a smart way to designate the steps of a given number, but, as always, when choosing between the method and the operator, it is important to write the code in the same style.

Increment and decrement

The increment and decrement operators change the numerical value of the change by one. The stench is represented by two pluses (++) and two minuses (-) and often vikoristovuyutsya in cycles.

Respect: the increment and decrement operators can only be changed in a different way. Trying to beat them with simple numbers will bring you to pardon.

7++
Uncaught ReferenceError: Wrong left side right move in postfix operation

The increment and decrement operators can be classified as prefix and postfix operations, depending on whether the operator is relative to the change location.

The prefix increment is written as ++x.

// Set a variable
let x = 7;

let prefix = ++x;
console log(prefix);
8

The value of x increased by 1. The postfix increment is written as y ++.

// Set a variable
let y = 7;
// Use the prefix increment operation
let postfix = y++;
console log(postfix);
7

The postfix operation didn't make a difference. The value will not be increased by doti, the docks of viraz will not be evaluated. For which it is necessary to run the operation dvіchі:

let y = 7;
y++;
y++;
console log(y);
8

Most of the qi operators are shortened in cycles. This cycle for the operator is run 10 times, starting from 0.

// Run a loop ten times
for (let i = 0; i< 10; i++) {
console log(i);
}
0
1
2
3
4
5
6
7
8
9

In this application, the iteration cycle is overridden by the additional increment operator.

Seemingly simpler, x++ can be shorthand in x = x + 1, and x is short in x = x - 1.

operator and attraction

One of the most famous operators is the attracted operator, which has already been mentioned in this manual. Vіn representations with the sign of equivalence (=). Symbol = vikoristovuєtsya for the designation of the right-handed zminnoї zlіva.

// Assign 27 to age variable
let age = 27;

The standard operator is assigned to JavaScript by a number of storage operators and attached to combine the arithmetic operator with the = operator.

For example, the operator to add a new value to the next value and to add to a new new value.

// Assign 27 to age variable
let age = 27;
age += 3;
console log(age);
30

Well, age += 3 is the same as i age = age + 3.

All arithmetic operators can be combined with the assignment operator. Below is a predefined table of operators assigned to JavaScript.

Warehouse operators are often used in loops as increments and decrements.

Operator priority

Operators rank in the order of precedence, like in superior mathematics.

For example, multiple may be the highest priority, lower addition.

// First multiply 3 by 5, then add 10
10 + 3 * 5;
25

Likewise, it is necessary to carry out the operation on the back, to take it in round arches - such operations may always be the highest priority.

// First add 10 and 3, then multiply by 5
(10 + 3) * 5;
65

Below you will find the JavaScript arithmetic operator precedence table. For postfix increment and decrement, higher priority is higher, prefix lower.

Increment/decrement, multiplication/rozpodіl and folding/removal may have the same equal priority.

The precedence may be not only arithmetic operators, but also assignment operators, logical operators, smart operators and then. The list can be viewed.

Tags:

Operator precedence

The precedence of the operations is the order in which the operations are ranked in folding folds. Operations of one equal may have the same precedence. Calculation is carried out on the basis of the right of all binary operations, starting from the operations, resurrected at the upper part of the list, and ending with operations in the lower part.

The precedence of operators, from lowest to highest will be advanced:

Assigned =+=-=*=/=%=<<=>>=>>>=&=^=|=

Viber for the mind? :

Logichne ABO ||

Logic I&&

Pobitov ABO |

Turned off by bit ^

Pobitov І&

Nerivnist! =

Rіvn_st / Nerіvnіst == !=

Porivnyannia<<=>> =

Bit by bit destruction<<>>>>>

Addition/withdrawal + -

Multiply/subdil * / %

Forbidden/additional/unary minus/increment/decrement! ~ - ++ -

Wiklik, overstrength of parameters () .

Reserved keywords in JavaScript.

JavaScript can be low reserved for keywords. There are three types of words: JavaScript words are reserved, words are reserved for a future word, and they are unique words for living. Keywords JavaScript

break false in this void

continue for new true while

delete function null typeof with

else if return var

JavaScript keywords for future zastosuvannya

case debugger export super

catch default extends switch

class do finally throw

const enum import try

Words, like varto uniquely live - tse tі, yakі vzhe can name the names of internal objects or functions of JavaScript. This includes words similar to String or parseInt.

The choice of any keyword from the first two categories will lead to a pardon when compiling, if the program is taken advantage of. Variation of reserved words from the third list can lead to misbehavioral problems, so you try to victorize your changed original primitives with the same names in one program. For example, the program is not working, those that you want:

var text = new String("This is a string object");

In this case, you take a pardon, as if to remind you about those that String is not an object. The richness of vipadkіv vikoristannya beforehand of a clear identifier is not so understandable.

Scenarios. Creation of scenarios.

JavaScript is my script (scripts), which is mainly used for creating interactive elements on Web-sides. You can tweak it to create a menu, check the correctness of filling in forms, change the image, or as much as you can on the Web side. If you look at GoogleMaps or Google's GMail service, you can get an idea of ​​what JavaScript is building today.

Since JavaScript is currently one of my scenarios, which is supported by all major Web browsers (InternetExplorer, Firefox, Netscape, Safari, Opera, Camino, etc.), it is widely accepted.

The JavaScript code is called by the client's Web browser, and in which case it is called a script on the client's side. In addition, the JavaScript code can also be hosted on a Web server to generate HTML documents by including server-side scripting. If you want JavaScript to be mixed with scripts on the client side, it's also harder on the server side.

When writing JavaScript code, you only need a text editor and a Web browser. Knowledge of HTML and CSS plays an incredibly positive role, and if you want to master the JavaScript skills on a Web site, then you also need a Web site. If you already have a Web site, that's awesome! Even though there are no personal, cost-free servers, you can win for hosting your own sides.

As for the text editor, Windows is the NotePad editor. If you want to be enough for editing JavaScript, HTML and CSS, a better editor, such as EditPlus or another, may appear handy.

Well, now you can go to the creation of the JavaScript script!

The first thing you need to know is how to add the JavaScript script to the HTML side. You can do this in one of two ways: put the Script tags on the Web site and put the JavaScript code in the middle of those tags, or put all the JavaScript code in a small file and link to it for help with the Script tag.

Whether any of these methods is entirely admissible, ale stinks may be recognized differently. For example, a small code, which will be featured only on one side, placing it between Script tags will be a good solution. However, if there is a large snippet of code that can be found on many sides, it might be better to put that JavaScript code into a smaller file and link to it. You should try so that it would not be necessary to capture this code quickly when viewing different sides. The code is hacked once and the browser saves a lot for the sleazy trick. It's similar to how cascading style sheets (CSS) are wicked.

Below are two ways to include JavaScript code:

Scenario functions.

You can design fragments of the output text as a function, calling this function, if necessary, in different places to the JavaScript script.

Sound functions are assigned to a section of the header of an HTML document marked with tags і. As we have already said, the function can be assigned before the weekly. Placement of all functions at the heading section of the HTML document guarantees the availability of these functions when processing the document.

An overview of the function representations below:

function im([parameter 1] [,parameter 2] [...,parameter N])

function body rows

All parameters are passed by value. Therefore, the function cannot be changed instead of the changed ones, as the same parameters are transferred.

With the help of the return keyword, the return function can also rotate a value.

Language JavaScript supports the principles of object-oriented programming. All objects that you can learn in robots can be divided into three great groups:

1. Vbudovanie ob'ekti movi. Numerous objects are recognized for working with other types of data or other typical tasks (for example, Math, String, Date and other objects). It is often necessary to create a different instance of the object (crim Math) before trying to find new objects.

2. Outstanding standard objects. Designated for interoperability with standard interface elements and browser functions. The same object as window, document and event. All called objects are available in any place of the script and do not affect the creation of instances.

3. Objects of Koristuvach. Created by a retailer for specific needs. The creation of powerful objects will require singing skills and the completion of the development.

Whether it be an object to take revenge on one's own authority and that method. The authority of the object is the most important parameter that determines the characteristics of the object. The method of the object is chosen as a diy, as it can be a visualization of the data of the object. If you look at the programming and look like an object of a great person, then your power will be "growth", "vaga", "colour of eyes", and methods - "є", "drink", "walk" and so on.

You can turn back to power or the method by specifying its name that instance of the object:

object.

object.method()

Such a notation (through a dot) allows you to uniquely designate an instance of the object, whose authority you want to use. In fact, the characteristics are set as if they were normally changed, and the methods - as if they were standard functions. To pay attention to the fact that the method may end up with shackles, so you do not pass the same parameters to the method. For example:

// Vicliche interpreter METHOD open()

// Shukatime interpreter Power open,

// do not know yogo and see a pardon

8. JavaScript special operators.

?: Allowing you to vikonati with a simple "if...then...else"

Evaluate two verses and rotate the result of another verse.

delete Allows deleting the authority of an object or an element with a sing array index.

new Allows you to create an object type that is considered to be colorful, or one of the object types.

this Keyword, so you can twist to jump to a stream object.

typeof Rotate a string to indicate the type of the unevaluated operand.

void The void operator determines which value to evaluate without turning the value.

9. Operator precedence in JavaScript.

Operator precedence

The precedence of the operations is the order in which the operations are ranked in folding folds. Operations of one equal may have the same precedence. Calculation is carried out on the basis of the right of all binary operations, starting from the operations, resurrected at the upper part of the list, and ending with operations in the lower part.

The precedence of operators, from lowest to highest will be advanced:

Assigned =+=-=*=/=%=<<=>>=>>>=&=^=|=

Viber for the mind? :

Logichne ABO ||

More logical &&&

Pobitov ABO |

Turned off by bit ^

Pobitov I &

Nerivnist! =

Rіvn_st / Nerіvnіst == !=

Porivnyannia<<=>> =

Bit by bit destruction<< >> >>>

Addition/withdrawal + -

Multiply/subdil * / %

Forbidden/additional/unary minus/increment/decrement! ~ - ++ -

Wiklik, overstrength of parameters () .

Virazi in JavaScript are combinations operandsі operators.

Operations in virazas, they win consecutively up to the value of priority (which is higher than the value of priority, tim vin vishchy). The result, which turns out, does not have a value of the same type as the type of obtained data. For example, in operations of rotation, operands of different types take part, but the result, which is rotated, will always be of a logical type.

Rice. 1. Structure of JavaScript Virase

Operandi- Data that are processed by JavaScript scripts. Like operands can be as simple as types of data, as well as folding, and also in other ways.

Operators- Tse symbols of mov, yakі vykonuyut different operations with danim. Operators can sign up for additional punctuation symbols or key words.

Depending on the number of operands, the following types of operators are distinguished:
unary- In the operation, one operand takes part;
binary- In the operation, two operands take part;
ternary- combines three operands.

The simplest form of expression literal- Look, what counts in itself, for example, the number 100, the row "Hellow world". You can also change it with a viraz, so that it will be counted at the nadan їй value.

Virazi and operators in JavaScript

1. Arithmetic operators

Arithmetic Operators are used for mathematical operations, they are used with numerical operands (or change, which take a numerical value), turning the result of a numerical value.

As if one of the operands is in a row, the JavaScript interpreter will try to convert it to a numeric type, and then we will convert the operation. It is impossible for type conversions to appear if the result is NaN (not a number).

Table 1. Arithmetic operators
Operator/Operation Description Priority
+ Addendum Adding numeric operands. If one of the operands is a row, then the result of virazu will be a row. 12
- Vidnimannya Vykonuє vіdnіmannya other operand from the first. 12
- Unary minus I turn a positive number into a negative one, and back and forth. 14
* Multiple Multiply two operands. 13
/ Podil Splitting the first operand into another. The result of the subdivision can be as a whole, and a number with a floating point. 13
% Delay per module Calculate the surplus, which is taken away when the first operand is subsumed to the other. Zastosovuetsya like up to integer numbers, so i up to a number with a floating point. 13
var x = 5, y = 8, z; z = x + y // Turn 13 z = x - y; // Turn -3 z = - y; // Turn -8 z = x * y; // Turn 40 z = x / y; // Rotate 0.625 z = y% x; // Turn 3

2. Operator and attraction

operator and attraction vikoristovuyutsya for assigning the meaning of change. Combined operators allow you to save the first and the next value in one change.

var a = 5; // Attract the changeable a numeric value 5 var b = "hellow"; // Take the row hellow into the change b var m = n = z = 10; // attract changing m, n, z numeric values ​​10 x + = 10; // equally x = x + 10; x -= 10; // equally x = x – 10; x * = 10; // equally x = x * 10; x /= 10; // equally x = x/10; x% = 10; // equally x = x%10;

3. Operators for increment and decrement

Operations increment and decrementє unary and increase and change the value of the operand by one. Like an operand can be changed, an element to an array, the power of an object. Most of these operations are carried out by increasing the amount of the lichnik in the cycle.

var x = y = m = n = 5, z, s, k, l; z = ++x * 2; /* Afterwards calculate the rotation values ​​z = 12, x = 6, then. the x value is incremented by 1, and then the multiplication operation */s = y++*2; /* Afterwards calculate the values ​​s = 10, y = 6, then. the multiplication operation is reduced, and after changing y, the increase by 1 value is taken */ k = --m * 2; // Rotate values ​​k = 8, m = 4 l = n-- * 2; // Rotate l = 10, n = 4

4. Operators of alignment

Operators matched for matching operands, the result of the match can be one of two values ​​- true or false. Operands can be not only numbers, but rows, logical values ​​and objects. Prote por_vnyannya can only be vikonuvatsya for numbers and rows, so the operands, like numbers and rows, are transformed.

Since both operands cannot be successfully converted to numbers or strings, the operators must always evaluate to false .

As a rule, operands are rows/numbers, or they can be converted into rows/numbers, they will be sorted like rows/numbers.

Whenever one operand is in a row/transformed into a row, and the last one is a number/transformed into a number, the operator tries to transform the row into a number and vice versa. If the row is not a number, it will change to NaN and the result will be false .

Most of the operations are broken up during the organization of the dressing of the programs.

Table 4
Operator/Operation Description Priority
== Equity Revіryaє dvі values ​​on zbіg, allowing for the conversion of types. Turn true if operands are avoided, and false if they stink differently. 9
!= Inconsistency Turn true because the operands are not equal 9
=== Identity Revіryaє two operands on "identity", keruyuchi suvorim zbіgu. Turn true to equal operands without rewriting types. 9
!== Not identical Vikonu reverku identichnosti. Turn true so operands are not equal without type conversion. 9
> More Turn true if the first operand is greater than the other, turn false otherwise. 10
>= More than one Turn true if the first operand is not less than the other, turn false otherwise. 10
Turn true if the first operand is less than the other, turn false otherwise. 10
Turn true if the first operand is not greater than the other, turn false otherwise. 10
5 == "5"; // Turn true 5! = -5.0; // Turn true 5 === "5"; // turn false false === false; // Turn true 1! == true; // Turn true 1! = true; // turn false, true shards turn to 1 3 > -3; // turn true 3> = "4"; // turn false

5. Logical operators

Logical operators allow you to combine minds that turn logical values. Most often they are victorious in the mental expression if.

(2 < 3) && (3===3); // вернет true, так как выражения в обеих скобках дают true (x < 10 && x >0); // Turn true so that the x value is between 0 and 10! false; // turn true

6. Bitwise operators

Bit operators process with operands as from a 32-bit sequence of zeros and ones and rotate the numerical value, which means the result of the operation, written in the tenth number system. Like the operands, the integers of the number are looked at, the fractional part of the operand is seen. Bitwise operations can be broken, for example, when ciphering data for robots with ensigns, delimiting access rights.

Table 6. Bitwise operators
Operator/Operation Description Priority
& Pobitovy I If the offense is more expensive 1 , then the resulting bit is more expensive 1 . Otherwise, the result is more 0 . 8
| Pobitovy ABO If one of the operands is replaced at position 1, the result will also be replaced by 1 at position 1, otherwise the result at position 1 will be equal to 0 . 6
^ VKlyuchne ABO If only one, and only one value, will revenge 1 in any position, then the result will revenge 1 in that position, in another case the result in that position will be 0. 7
~ Restricted The operation of bit-by-bit enumeration over two-valued expressions of the value of the virus is completed. Be it a position that avenges 1 from the outer expression, it will be replaced by 0 . Whether it be a position that avenges 0 in the outward direction, it is good 0 . Positive numbers start from 0 , negative numbers - from -1 to that ~ n == -(n+1) . 14
The operator sets the bits of the first operand to the left by the number of bit positions inserted by the other operand. To fill in the positions of the right hand, zeros are used. Rotate the result to the same type as the left operand. 11
>> Pobitovy zsuv right-hander The operator sets bits of the first operand to the right the number of bit positions inserted by the other operand. Figures, zsunutі between the range, are seen. The highest bit (32nd) is not changed to save the sign of the result. Since the first operand is positive, the older bits of the result are filled with zeros; Since the first operand is negative, the older bits of the result are filled with ones. Zsuv value to the right by one position is equivalent to the subdivision by 2 (with an excess), and suvi to the right by two positions is equivalent to the subdivision by 4 and so on. 11
>>> Pobitovy zsuv right-handed without a badge The operator sets bits of the first operand to the right the number of bit positions inserted by the other operand. Livoruch add zeros independently of the sign of the first operand. Figures, zsunutі between the range, are seen. 11
var x = 9, y = 5, z = 2, s = -5, result; // 9 is equivalent to 1001; 5 is equivalent to 0101 result = x & y; // Rotate 1 (equivalent to 0001) result = x | y; // Turn 13 (equivalent to 1101) result = x ^ y; // turn 12 (equivalent to 1100) result = ~ y; // Rotate -6 (equivalent to 1100) result = x<< y; // вернет 288 (эквивалентно 100100000) result = x >>z; // Turn 2 (equivalent to 10) result = s >>> z; // turn 1073741822 (equivalent to 111111111111111111111111111110)

7. String Operators

Іsnuє kіlka operіv, yakі pratsyuyut іz ranks special rank.

"1" + "10"; // Rotate "110" "1" + 10; // Turn "110" 2 + 5 + "coloured olives"; // Turn "7 colorful olives" "Colorful olives" + 2 + 5; // Turn "Colorful olives 25" "1" > "10"; // turn false "10"<= 10; // вернет true "СССР" == "ссср"; // вернет false x = "micro"; x+= "soft"; // вернет "microsoft"

8. Special operators

Table 8. Special operators
Operator/Operation Description Priority
. Zvernennya to the bitterness Zdiysnyuє access to the quality of the object. 15
, Multiple calculation Counting the number of independent viruses recorded in one row. 1
Array indexing Creates access to the elements of the array or the authorities of the object. 15
() Weekly functions, grouping Group operations that call a function. 15
typeof Assigns data type The unary operator rotates the data type of the operand. 14
instanceof Object type revalidation Operator perevіryaє, chi є ob'єkt instance of the first class. The left operand can be an object, the right operand is guilty of revenge on the class of objects. The result will be true , which means that the object is left-handed, it is an instance of the class assigned to right-handed, otherwise it is false . 10
in Rechecking the visibility of the quality Like the left operand can be a row, but the rule is an array or an object. If the value is the same as the power of the object, the result is true to rotate . 10
new Creation of an object The operator creates a new object with insignificant powers, then calls the constructor function of its initialization (parameter passing). You can also zastosovuvatsya to create an array. 1
delete Vidal The operator allows you to see the power of an object or an element from an array. Turn true if the delete was successful, otherwise false . At the time of the appearance of the element, the array of yoga does not change. 14
void Significance of a virazu without a value, what to turn Unary operator that returns the value of an operand and rotates underfined . 14
?: Operation mental expression The ternary operator allows you to organize a simple layout. Three operands take part in the viraz, the first one is guilty of but logical values, or it is transformed into a new one, and the other and the third - whether they are values. If the first operand is equal to true, then the smart one will be aware of the value of the other operand; if false - then the third. 3
document.write("hello world"); // Display row hello world i = 0, j = 1; // take the change values ​​function1(10, 5); // function wiki function1 with parameters 10 and 5 var year = ; // Create array with elements typeof (a:1); // Rotate "object" var d = new Date(); // create a new object behind the help constructor Date() d instanceof Date; // turn true var mycar = (make: "Honda", model: "Accord", year: 2005); "make" in mycar; // Turn true var obj = new Object (); // create an empty object var food = ["milk", "bread", "meat", "olive oil", "cheese"]; delete food; // See the fourth element in the food x > 10 array? x*2: x/2; // rotate value x * 2, if x > 10, otherwise x / 2

9. Comments in JavaScript

One-row comment: before the text of the comment it is necessary to put the symbol // .

The operator is the symbol(s) or the key word, the zavdyaks are viroblyayutsya deyaki see the calculation for the fate of one or the number of values. Values, roztashavani levoruch і pravoruch in the type of the operator, are called operands. An operator with one operand is called unary, with two-binary, with three-ternary.

Operators can automatically change the types of their operands as the world needs them. For example, the multiplication operator * evaluates numbers, so "2" * "3" is considered as a valid reason because the interpreter sees implicitly converting rows in a number.

Operator priority

Operator priority- the purpose of the operator's power, which adds to the callousness of the voicing of the number of different operators for the presence of an explicit statement, the order of their calculation. Operators with higher high priority are beaten before operators with lower priority.

At the Operator column, a three-marked box shows the expansion of the operands of the operator's choice.

Column A has an operator associative property. Associativity- the same order, in which operators with the same priority are processed. For example, the operator can be associative to the right, so there are two equivalents:

X - y - z (x - y) - z

The operator is attracted to be associative right-handed, so there are two equivalents:

W = x = y = z w = (x = (y = z))

The column Pro has the number of operands assigned.

In the Type column, the value before the arrow indicates the type of operands, and after the arrow, the type of value to be rotated.

lval (abbreviation for left value) – left-sided viraz. This is a historical term, which means viraz, which can be levoruch as an operator of attraction. Left-sided virazi: change, power of objects and elements of arrays.

In the tables below, the operators are repaid as a change in priority, the horizontal lines indicate groups of operators with a different priority.

Operator Operator type A Pro tipi value
(…) Grouping Daily
1 be yake → be yake
… . …
… […]
new ... ()
access operator
access operator
new (with a list of arguments)
angry to the right
angry to the right
Daily
2
2
1
lval, lval → whatever
lval, row chi number → whatever
constructor → object
… ()
new …
Wiklik functions
new (no arguments)
angry to the right
to the right
1
1
function → whatever
constructor → object
… ++
… --
Postfix increment
Postfix decrement
Daily
Daily
1
1
lval → number
lval → number
! …
~ …
+ …
- …
++ …
-- …
delete …
typeof …
void...
Logical NOT (inversion)
Pobitov NOT (inversion)
Unary plus
Unary minus
Prefix increment
Prefix decrement
Vidalennya
Specifies the type of data
Rotation of an unknown value
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
1
1
1
1
1
1
1
1
1
be-yaké → boulovo
tsile → tsile
number → number
number → number
lval → number
lval → number
lval → bulovo
be-yake → row
be-yake → undefined
… ** …
… * …
… / …
… % …
Zvedennya in the foot
Reproduction
Podil
Podіl iz too much
to the right
angry to the right
angry to the right
angry to the right
2
2
2
2
number, number → number
number, number → number
number, number → number
number, number → number
… + …
… - …
… + …
Addition
Vidnimannya
concatenation
angry to the right
angry to the right
angry to the right
2
2
2
number, number → number
number, number → number
row, row → row
… << …
… >> …
… >>> …
Zsuv bіtіv vlіvo
Zsuv bitiv pravoruch іz saving sign
Zsuv bitiv pravoruch іz filled with zeros
angry to the right
angry to the right
angry to the right
2
2
2
tsile, tsile → tsile
tsile, tsile → tsile
tsile, tsile → tsile
… < …
… <= …
… > …
… >= …
… in …
… instanceof …
Less lower
Less or more expensive
More below
More or more
Re-verification of the obviousness of the quality
Re-checking for validity up to which type
angry to the right
angry to the right
angry to the right
angry to the right
angry to the right
angry to the right
2
2
2
2
2
2
number, number → boolean
number, number → boolean
number, number → boolean
number, number → boolean
row, object →
object, constructor → boolean
… == …
… != …
… === …
… !== …
Rivne
Not healthy
Strictly one
Strictly not one
angry to the right
angry to the right
angry to the right
angry to the right
2
2
2
2
be-yake, be-yake → boolean
be-yake, be-yake → boolean
be-yake, be-yake → boolean
be-yake, be-yake → boolean
… & … Pobitov I angry to the right 2 tsile, tsile → tsile
… ^ … Pobytove KEY ABO angry to the right 2 tsile, tsile → tsile
… | … Operation from allies
Operation from allies
Operation from allies
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
to the right
2
2
2
2
2
2
2
2
2
2
2
2
2
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
lval, be yake → be yake
yield …
yield* ...
yield
yield*
to the right
to the right
1
1
... … Expansion Daily 1
… , … Coma angry to the right 2 be yake, be yake → be yake