Meta tags:
Headings (most frequently used words):
the, javascript, operator, operators, for, web, arithmetic, objects, basic, summary, chapter, article, toc, about, getting, started, basics, control, structures, data, types, built, in, functions, classes, error, handling, regular, expressions, general, bom, dom, addition, subtraction, multiplication, division,
Text of the page (most frequently used words):
the (51), #operator (24), let (24), javascript (22), operators (22), you (18), and (15), alert (13), numbers (13), with (11), introduction (11), can (9), for (8), arithmetic (8), try (8), this (7), that (7), types (7), math (6), well (6), them (6), will (6), subtraction (6), variables (6), answer (6), just (6), all (6), string (6), into (5), doing (5), basic (5), division (5), result (5), use (5), instead (4), object (4), when (4), number (4), example (4), text (4), two (4), values (4), add (4), methods (4), functions (4), tutorial (3), article (3), not (3), here (3), increment (3), decrement (3), comparison (3), easy (3), are (3), but (3), errors (3), multiplication (3), convert (3), other (3), like (3), strings (3), simple (3), addition (3), about (3), web (3), regular (3), expressions (3), conditional (3), catching (3), following (2), languages (2), your (2), language (2), quite (2), there (2), each (2), get (2), summary (2), throwing (2), return (2), something (2), zero (2), programming (2), see (2), saw (2), than (2), mix (2), because (2), subtract (2), behavior (2), bit (2), chapter (2), data (2), handling (2), asp (2), net (2), dom (2), window (2), bom (2), search (2), error (2), catch (2), fields (2), inheritance (2), getters (2), setters (2), prototypes (2), objects (2), function (2), parameters (2), optional (2), chaining (2), nullish (2), coalescing (2), ternary (2), remainder (2), logical (2), modify (2), assign (2), assignment (2), array (2), basics (2), loops (2), statement (2), toc (2), localization, suggest, correction, contact, com, 2007, 2026, has, been, fully, translated, preferred, list, help, translate, click, italian, czech, next, previous, hopefully, illustrated, examples, above, known, operations, might, want, perform, few, more, related, articles, special, global, called, infinity, usually, requires, extra, attention, some, actually, throw, exception, halt, execution, impossible, task, dividing, however, harsh, run, any, before, calculation, again, actual, containing, multiplying, converts, realizes, trying, now, changed, added, different, works, differently, participating, members, make, operation, possible, subtracting, minus, combined, created, remember, changes, case, treat, concatenate, talked, illustrate, adding, very, plus, find, four, multiply, divide, quickly, have, look, one, dig, through, abstraction, layers, bottom, pure, therefore, come, big, surprise, course, kinds, fact, many, found, calculator, they, mostly, exact, same, thing, wpf, php5, jquery, html5, css3, webforms, mvc, location, history, script, tag, general, replace, using, capturing, groups, match, regex, flags, options, finally, static, classes, extension, property, accessors, properties, multiple, recursive, callback, anonymous, default, json, date, built, type, conversion, null, undefined, booleans, while, switch, control, structures, truthy, falsy, syntax, hello, world, tools, need, getting, started, libraries, webbrowser, what, table, contents, complete,
Text of the page (random words):
arithmetic operators the complete javascript tutorial javascript tutorial toc table of contents chapter article toc introduction the assignment operator comparison operators arithmetic operators basic arithmetic operators the addition operator the subtraction operator the multiplication operator the division operator summary increment decrement operators modify and assign operators logical operators remainder operator conditional ternary operator nullish coalescing operator optional chaining operator about javascript what is javascript javascript and the webbrowser javascript libraries getting started the tools you need hello world the basics basic javascript syntax variables truthy falsy control structures the if statement the switch statement loops for and while loops for of and for in data types introduction booleans numbers strings null undefined type conversion built in objects introduction number string array the basics array methods date math json operators introduction the assignment operator comparison operators arithmetic operators increment decrement operators modify and assign operators logical operators remainder operator conditional ternary operator nullish coalescing operator optional chaining operator functions introduction function parameters function parameters with default values anonymous functions callback functions recursive functions multiple return values objects introduction properties methods property accessors getters setters prototypes prototypes inheritance extension classes introduction fields methods getters setters inheritance static fields methods error handling introduction catching errors try catch catching throwing errors try catch finally error types conditional catching regular expressions introduction regex flags options search match with regular expressions using capturing groups search replace with regular expressions javascript for web general introduction window dom bom the script tag javascript for web the bom the window object the history object the location object javascript for web the dom introduction javascript asp net mvc asp net webforms c css3 html5 jquery php5 wpf operators arithmetic operators programming is when you dig through all the abstraction layers and get to the bottom all about handling 1 s and 0 s it s pure math therefore it can t come as a big surprise that you can of course do all kinds of math with javascript in fact many javascript operators can be found as operators on a simple calculator as well and they ll mostly do the exact same thing basic arithmetic operators you ll find all the four basic arithmetic operators in javascript add subtract multiply and divide let s quickly have a look at each one of them the addition operator adding two numbers in javascript is very simple just use the add plus operator you can use numbers like this let result 2 3 alert result or you can use variables like this let a 2 b 3 let c a b alert c just remember that the behavior of the add operator changes if you mix in other types e g a string in that case the add operator will treat all values as string and concatenate them instead of doing math on them we talked a bit about this in the chapter on data types but let s just illustrate with an example let a 2 b 3 let c a b alert c the result here is not 5 but instead 23 because a combined text string of 2 and 3 are created as a result of the addition the subtraction operator subtracting two numbers is just as easy just use the subtraction minus operator let answer 5 2 alert answer or you can use variables let a 5 b 2 let c a b alert c now we saw that the behavior changed when we added two variables of different types e g a string and a number the subtraction operator works a bit differently it will instead try to convert participating members into numbers to make the subtraction operation possible let a 5 b 2 let c a b alert c the result here is 3 just as in the example with all numbers because javascript converts the text string of 5 into a number of 5 when it realizes that you are trying to subtract the two values the multiplication operator multiplying numbers is simple as well let answer 5 2 alert answer and again you can do it with actual numbers or variables containing numbers let a 5 b 2 let c a b alert c if you mix in other types than numbers e g text strings javascript will try to convert them for you before doing the calculation let a 5 b 2 let c a b alert c the division operator doing division in javascript is quite easy as well as you can see in this example let answer 10 2 alert answer with numbers as well as with variables let a 10 b 2 let c a b alert c as we saw with subtraction and multiplication javascript will try to convert any other types than numbers like text strings into numbers if you try to do division with them let a 10 b 2 let c a b alert c something that usually requires extra attention when doing division is the number of 0 zero some programming languages will actually throw an exception and halt execution if you try to do the impossible task of dividing something by zero however javascript is not that harsh as you can see if you try to run this example let a 10 b 0 let c a b alert c instead of throwing errors it will return the special global object called infinity summary doing math in javascript is quite easy as i ve hopefully illustrated in the examples above there s a well known operator for each of the basic arithmetic operations you might want to perform there are a few more math related operators but we ll get to them as well in the following articles comparison operators previous increment decrement operators next this article has been fully translated into the following languages czech italian is your preferred language not on the list click here to help us translate this article into your language javascript tutorial com 2007 2026 contact us suggest correction localization
|