﻿ Divide ﻿

Main Page

# Divide

Divide
The divide operator is represented by a slash (
/
) and divides the first operand by the second operand:
var iResult = 66 / 11;
The divide operator, like the multiply operator, has special behaviors for special values:
?
If the operands are numbers, regular arithmetic division is performed, meaning that two posi-
tives or two negatives equal a positive, whereas operands with different signs yield a negative.
If the result is too high or too low, the result is either
Infinity
or –
Infinity
.
?
If either operand is
NaN
, the result is
NaN
.
?
If
Infinity
is divided by
Infinity
, the result is
NaN
.
?
If
Infinity
is divided by any number, the result is
Infinity
.
?
Division of a non-infinite number by 0 always equals
NaN
.
?
If
Infinity
is divided by any number other than 0, the result is either
Infinity
or –
Infinity
, depending on the sign of the second operand.
Modulus
The modulus (remainder) operator is represented by a percent sign (
%
) and is used in the following way:
var iResult = 26 % 5; //equal to 1
Just like the other multiplicative operators, the modulus operator behaves differently for special values:
?
If the operands are numbers, regular arithmetic division is performed, and the remainder of that
division is returned.
?
If the dividend is
Infinity
or the divisor is 0, the result is
NaN
.
?
If
Infinity
is divided by
Infinity
, the result is
NaN
.
?
If the divisor is an infinite number, the result is the dividend.
?
If the dividend is 0, the result is 0.
The additive operators, add and subtract, are typically the simplest mathematical operators in program-
ming languages. In ECMAScript, however, a number of special behaviors are associated with each
operator.
The add operator (
+
) is used just as one would expect:
var iResult = 1 + 2;
47
ECMAScript Basics
05_579088 ch02.qxd 3/28/05 11:35 AM Page 47 Free JavaScript Editor     Ajax Editor
{"ft_lang_label":"__label__en","ft_lang_prob":0.84899044,"math_prob":0.97902673,"size":1929,"snap":"2019-13-2019-22","text_gpt3_token_len":485,"char_repetition_ratio":0.19116883,"word_repetition_ratio":0.22063038,"special_character_ratio":0.24727838,"punctuation_ratio":0.15281501,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9994609,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-23T11:40:35Z\",\"WARC-Record-ID\":\"<urn:uuid:30d8edbf-79de-464d-998a-dd171814e22f>\",\"Content-Length\":\"12693\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:968d8be7-abd1-49f1-a4e2-6a053657d024>\",\"WARC-Concurrent-To\":\"<urn:uuid:0e0b1ca2-f1f7-47b8-9ea8-0fd0ad2c1677>\",\"WARC-IP-Address\":\"173.249.8.108\",\"WARC-Target-URI\":\"http://www.yaldex.com/javascript-tutorial-4/pg_0075.htm\",\"WARC-Payload-Digest\":\"sha1:ZKYHRW26XBG2XVRYKL66EP5T3M7L5NP7\",\"WARC-Block-Digest\":\"sha1:4KY4YABO2GLDRAZKOV6F2XAOKXDLBF3H\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912202781.83_warc_CC-MAIN-20190323101107-20190323123107-00046.warc.gz\"}"}