57 JavaScript operaatorid
Operaatorid on tehtemärgid väärtuste arvutamiseks või võrdlemiseks. Vastavalt läbiviidavale tehtele jagunevad operaatorid mitmesse liiki, millest olulisemad on
- aritmeetika
- võrdlus
- loogika
- omistamine
Aritmeetikatehted
| Operaator | Seletus | Näide (y = 5) | Tulemus |
| + | Liitmine | x = y + 2 | x = 7 |
| – | Lahutamine | x = y – 2 | x = 3 |
| * | Korrutamine | x = y * 2 | x = 10 |
| / | Jagamine | x = y / 2 | x = 2.5 |
| % | Jagamise jäägi leidmine | x = y % 2 | x = 1 |
| ++ | Suurendamine ühe võrra | x = ++y | x = 6 |
| — | Vähendamine ühe võrra | x = –y | x = 4 |
Võrldustehted
Võrdlusoperaatorid võrdlevad operande ja väljastavad tõeväärtuse TRUE või FALSE vastavalt sellele kas võrdlus on tõene või väär.
| Operaator | Seletus | Näide ja tulemus (x = 5) |
| == | võrdne | x == 8 tulemus false |
| === | täpselt võrdne | x === 5 tulemus true x === ”5″ tulemus false |
| != | mittevõrdne | x != 8 tulemus true |
| > | suurem kui | x > 8 tulemus false |
| < | väiksem kui | x < 8 tulemus true |
| >= | suurem või võrdne | x >= 8 tulemus false |
| <= | väiksem või võrdne | x <= 8 tulemus true |
Loogikatehted
Loogikaoperaatorid võrdlevad mitut tingimust ja väljastavad tõeväärtuse.
| Operaator | Seletus | Näide ja tulemus (x = 6; y = 3) |
| && | NING | (x < 10 && y > 1) tulemus true |
| || | VÕI | (x == 5 || y == 5) tulemus false |
| ! | EITUS | !(x == y) tulemus true |
Omistamine
Omistamisoperaatori abil määratakse muutujale väärtus.
| Operaator | Näide (x = 10; y = 5) | Sama kui … | Tulemus |
| = | x = y | x = y | x = 5 |
| += | x += y | x = x + y | x = 15 |
| -= | x -= y | x = x – y | x = 5 |
| *= | x *= y | x = x * y | x = 50 |
| /= | x /= y | x = x / y | x = 2 |
| %= | x %= y | x = x % y | x = 0 |