Remainder (%) (Operator/multiplicative)

The % operator yields the remainder after dividing the left operand by the right. This is otherwise

known as the modulo or modulus operator.

In an ECMAScript compliant interpreter, the remainder is a floating-point value and, unlike the C

and C++ languages, the input operands can also be floating point values.

The result of performing a remainder on floating point values is not the same as the IEEE 754

remainder operation. IEEE 754 mandates a remainder computed via a rounding division whereas

ECMA mandates a truncating remainder. In ECMAScript the remainder behaves similarly to the Java

integer remainder operator and is analogous to the fmod() library function in C language compilers.

The behavior in an ECMA complaint JavaScript implementation should obey these rules:

❑If either operand is NaN then the result is NaN.

❑The sign of the result is the same as the sign of the dividend (the operand on the left).

❑If the dividend is an infinity, the result is NaN.

❑If the divisor is zero, the result is NaN.

❑If the dividend is a finite value and the divisor is infinity, the result equals the dividend.

❑If the dividend is zero and the divisor is finite, the result is zero.

Otherwise, as long as neither an infinity, zero or NaN is involved, the floating remainder is

calculated like this. The dividend n is divided by the divisor d to produce a quotient, q. The

quotient is forced to be an integer and multiplied again by d and the result subtracted from n to

yield the remainder. Thus:

q = n/d

r = n – (d * q)

The value q will be forced to be an integer although the resulting value r may not be.

The associativity is left to right.

Refer to the operator precedence topic for details of execution order.

R - Remainder then assign (%=) (Operator/assignment)

1815

Warnings:❑JScript version 1.0 truncates floating-point values to integers before applying the remainder

operator. This means that the expression 5.5 % 2.2 yields the value 1.

See also: Arithmetic operator, Associativity, Divide (/), Divide then assign (/=), Integer

arithmetic, Integer-value-remainder, Math.ceil(), Math.floor(), Multiplicative

expression, Multiplicative operator, Operator Precedence, Remainder then assign (%=)

Cross-references:ECMA 262 edition 2 – section – 11.5.3

ECMA 262 edition 2 – section – 11.13

ECMA 262 edition 3 – section – 11.5.3

Wrox Instant JavaScript – page – 19

Remainder then assign (%=)

(Operator/assignment)Divide one operand by another, leaving the remainder in the first.

Availability: ECMAScript edition – 2

JavaScript – 1.0

JScript – 1.0

Internet Explorer – 3.02

Netscape – 2.0

Netscape Enterprise Server – 2.0

Opera – 3.0

Property/method value type: Number primitive

JavaScript syntax: - anOperand1 %= anOperand2

anOperand1 The dividend value where the result is also

assignedArgument list:

anOperand2 The divisor value

Divide the left operand by the right operand and assign the remainder to the left operand.

This is functionally equivalent to the expression:

anOperand1 = anOperand1 % anOperand2;

Although this is classified as an assignment operator it is really a compound of an assignment and

a multiplicative operator.

JavaScript Programmer’s Reference

1816

The associativity is right to left.

Refer to the operator precedence topic for details of execution order.

The new value of anOperand1 is returned as a result of the expression.

Warnings:❑The operand to the left of the operator must be an LValue. That is, it should be able to take an

assignment and store the value.

operator, Associativity, Integer arithmetic, Integer-value-remainder, LValue,

Math.ceil(), Math.floor(), Multiplicative operator, Operator

Precedence, Remainder (%)

Cross-references:ECMA 262 edition 2 – section – 11.13

ECMA 262 edition 3 – section – 11.13

request object (Object/NES)A server-side object maintained by NES for each HTTP: request.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

JavaScript syntax: NES request

Object properties: <input_name>, <urlExtension>, agent, imageX, imageY,

ip, method, protocol

Whenever a user requests a page from a Netscape Enterprise Server, a request object is created to

manage storage, methods and properties for that request. When the request is returned, the object

can be destroyed as it will have no further use.

The request object contains details of the URL, form data and search criteria. This is the way that

you access the data in a form submit for example.

There are other properties belonging to this object that can tell you a lot about the client and what

is happening there.

The ASP server also supports a Request object, whose name is capitalized. It’s there for the same

purpose and manages the incoming requests from the the clients’ browsers.

Warnings:❑The Request object supported by ASP is quite different to that supported by NES. Since the tag

introducer is quite different for each server-side system, it is unlikely you’ll deploy common scripts

across NES and ASP running on IIS.

unwatch(), watch()

R - request.<input_name> (Property)

1817

Property JavaScript JScript NES Notes

<input_name> 1.1 +  - 2.0 + -

<urlExtension> 1.1 +  - 2.0 + -

agent 1.1 +  - 2.0 + -

imageX 1.1 +  - 2.0 + -

imageY 1.1 +  - 2.0 + -

ip 1.1 +  - 2.0 + Warning

method 1.1 +  - 2.0 + -

protocol 1.1 +  - 2.0 + -

request.<input_name> (Property)Input elements can be accessed associatively by name.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: String primitive

JavaScript syntax: NES request.anInputElement

Argument list: anInputElement The value of the NAME="..." tag attribute

The NAME="..." attribute of an <INPUT> element in a <FORM> can be used as a key to access the

item as a property of the request object.

For example, a text filed can be created like this:

<INPUT NAME="MyNamedTextObject" TYPE="TEXT">

You can then access it as a property belonging to the response with this object and property reference:

response.MyNamedTextObject

request.<urlExtension> (Property)Additional properties can be passed from URL extensions.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: String primitive

JavaScript syntax: NES request.<urlExtension>

When you submit a request, you can pass parameter values in the request with a special coding

technique that allows them to convey information in the URL that is reflected into special

properties in the request object.

JavaScript Programmer’s Reference

1818

The question mark (?) is the control sequence introducer for this. Sometimes these values are

referred to as the query or search portion of the URL when they are accessed as properties of an

Anchor, Url, or Area object in the client.

The properties are then added as a name=value pair with multiple name=value pairs separated

by an ampersand (&) character.

request.agent (Property)A string containing the user agent details.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: String primitive

JavaScript syntax: NES request.agent

This property contains the name and version of the client software making the request. This is a

means of building client user agent dependent responses that deliver pages that are tailored to the

particular browser being used.

You might use this to respond with a Netscape Navigator version of a page that behaves differently

to the page you return to a user who requested the page from an MSIE browser.

request.imageX (Property)The X coordinate of the mouse when an image map is clicked on.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: Number primitive

JavaScript syntax: NES request.imageX

If a client-side input object whose type is "image" was used, this is the horizontal coordinate value

of the mouse relative to the origin of the image when the user clicked the button on the image.

This would have been placed into the page with a tag like this:

<INPUT TYPE="image" NAME="imageName" SRC="...">

R - request.imageY (Property)

1819

request.imageY (Property)The Y coordinate of the mouse when an image map is clicked on.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: Number primitive

JavaScript syntax: NES request.imageY

If a client-side input object whose type is "image" was used, this is the vertical coordinate value of

the mouse relative to the origin of the image when the user clicked the button on the image.

This would have been placed into the page with a tag like this:

<INPUT TYPE="image" NAME="imageName" SRC="...">

request.ip (Property)The IP address of the client.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: String primitive

JavaScript syntax: NES request.ip

IP addresses are interesting and useful if you know their provenance but should not be relied upon

to uniquely identify a user.

Warnings:❑Be careful when using this value. Proxy servers and firewalls can modify the value you actually see

and can completely mask the IP address of the client. This can make all users behind the firewall or

proxy appear to be using the same machine.

❑Multiple users running Netscape Navigator via an X-Windows environment may indeed all

be running the browser core on the same machine and only viewing the windows on their

desktop systems.

❑Finally, clients connected via an ISP may have floating IP address values and may be served through

proxy and firewall systems. Indeed, some ISP-based users may even submit each request during a

session through a different firewall. The session state can then only be identified by means of hidden

values in the URL or with a cookie.

JavaScript Programmer’s Reference

1820

request.method (Property)The request method determines to some extent how a server should respond to the request.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: String primitive

JavaScript syntax: NES request.method

The request method could be one of the following:

❑get

❑post

❑put

❑delete

❑options

❑trace

These values may be in upper or lower case so you should use a case-insensitive test if you need to

check them.

request.protocol (Property)The client may not support all the available protocols. This is the level of HTTP protocol that the

client is prepared to accept.

Availability: JavaScript – 1.1

Netscape Enterprise Server – 2.0

Property/method value type: String primitive

JavaScript syntax: NES request.protocol

HTTP/1.1 protocol is much more efficient than HTTP/1.0 because it reduces the number of TCP

connections required. However, not all browsers support it and you may need to check this value if

you are sending back multiple items in a single response.

R - Request-response loop (Definition)

1821

Request-response loop (Definition)The mechanism by which a web server handles a request and serves a page back to a browser.

The web browser sends a request to a web server. This is passed to the middleware application

server which may create a special object to represent the request. Values passed to the web server

by the browser will be reflected as properties of that request object.

This mechanism will invoke an appropriate handler. That handler may be compiled code or

perhaps a script, possibly written in JavaScript in some middleware implementations.

As the handler is invoked, it is passed the request object and also an empty response object. The

handler then populates the response object with headers and body contents. This may be done by

means of property accessors or method calls.

Eventually the response is despatched back to the requesting browser. At this point some clean-up

takes place, the request logging takes place and the request response loop is completed.

Requesting privileges (Security related)Your script needs to request privileges when it requires them.

So long as you can sign scripts for Netscape Navigator, you can then make requests for privileges

when those scripts run. This is done by means of the privilege manager.

Because the Netscape Navigator security model is based on the Java security model, the Netscape

Navigator browser requests its privileges through the Java mechanisms. These are encapsulated in

a class that you can access from inside JavaScript.

The downside of this is that there is no meaningful value returned when the request is made. If the

request for a privilege is denied, the error causes a Java exception which is difficult to trap from

JavaScript. It is possible that new browser versions will support an exception handling mechanism.

There are two principle methods that are useful here, one to request the privilege and the other to

relinquish it.

enablePrivilege() – Requests the privilege passed as a string argument

disablePrivilege() – Relinquishes the privilege based on a string argument

Example code:

PrivilegeManager.disablePrivilege(),

PrivilegeManager.enablePrivilege(), Signed scripts,

UniversalSendMail

JavaScript Programmer’s Reference

1822

Reserved Word (Definition)JavaScript reserves certain words and maps computational functionality to them.

Availability: ECMAScript edition – 2

Reserved words are keywords that the interpreter uses to determine the instructions your script is

going to execute.

Generally, reserved words will be one of the following:

❑A keyword

❑A reserved word

❑A null literal

❑A Boolean literal

Here is a complete list of reserved words as defined by the ECMA 262 standard. It also includes

words that are dangerous because they are properties or method names.

Name Notes

abstract Java keyword reserved

arguments Identifier name

Array Object type

blur Identifier name

boolean Java keyword reserved

Boolean Object type

break Keyword

byte Java keyword reserved

callee Identifier name

caller Identifier name

captureEvents Identifier name

case Keyword

catch Reserved word

char Java keyword reserved

class Reserved word

clearInterval Identifier name

clearTimeout Identifier name

close Identifier name

closed Identifier name

Table continued on following page