About This Product
FontsMadeEasy.com
 
Search This Database:
| Over 5000 Free Fonts | Tutorials | Javascript Forum | Other Javascript Resources | Cheat Sheet
Tutorial archive
General Questions
Javascript 1.2
Navigation
Numbers
Strings
Object Model
Reference Manual
Dialog
Windows
Frames
Forms
Images
Mouse Events
Colors
File Access
Control Status Bar
Dates and Time
Cookies
Client Information
Bookmarklets







[Contents] [Previous] [Next] [Last]


Chapter 8

Operators

This section provides information about changes to the equality operators and the new delete operator.

Equality Operators

If the <SCRIPT> tag uses LANGUAGE=JavaScript1.2, the equality operators (== and !=) work differently. This section describes how the equality operators work without LANGUAGE=JavaScript1.2 and how they work with LANGUAGE=JavaScript1.2. For instructions on writing code to convert strings and numbers, see "Data Conversion".

Equality Operators Without LANGUAGE=JavaScript1.2

The following describes how the equality operators (== and !=) worked in previous versions of JavaScript and how they work in JavaScript 1.2 when LANGUAGE=JavaScript1.2 is not used in the <SCRIPT> tag. Note that if LANGUAGE=JavaScript, and LANGUAGE=JavaScript1.1 are used, the equality operators maintain their previous behavior.

Equality Operators With LANGUAGE=JavaScript1.2

If LANGUAGE=JavaScript1.2 is used in the <SCRIPT> tag, the equality operators (== and != ) behave as follows:

This approach avoids errors, maintains transitivity, and simplifies the language.

Data Conversion

To write JavaScript code that converts strings to numbers and numbers to strings in the different versions of Navigator, follow these guidelines:

When writing for all versions of Navigator:

  • To convert x to a string, use " " + x. For example,
    "" + 3 == "3"
  • To convert x to a number, use (x - 0). For example,
    "3" - 0 == 3
  • To convert x to a Boolean, use !!x. For example,
    !!null == false

When writing for Navigator 4.0 only:

  • To convert x to a string, in addition to " " + x, you can use String(x). For example,
    var x = 3
    String(x) = "3"
  • To convert x to a number, in addition to (x - 0), you can use Number(x). For example,
    var x = "3"
    Number(x) = 3
  • To convert x to a Boolean, in addition to !!x, you can use Boolean(x). For example,
    var x = null
    Boolean(x) = false

Example

The following example demonstrates the == operator with different <SCRIPT> tags.

This script Produces this output
<SCRIPT>
document.write("3" == 3);
</SCRIPT>
true
<SCRIPT>
document.write(("3"-0) == 3);
</SCRIPT>
true
<SCRIPT LANGUAGE="JavaScript">
document.write("3" == 3);
</SCRIPT>
true
<SCRIPT LANGUAGE="JavaScript1.1">
document.write("3" == 3);
</SCRIPT>
true
<SCRIPT LANGUAGE="JavaScript1.2">
document.write("3" == 3);
</SCRIPT>
false
<SCRIPT LANGUAGE="JavaScript1.2">
document.write(("3"-0) == 3);
</SCRIPT>
true
<SCRIPT LANGUAGE="JavaScript1.2">
document.write(String(3) == "3");
</SCRIPT>
true

delete

Core operator. Deletes an object's property or an element at a specified index in an array.

Syntax

delete objectName.property
delete objectname[index]
delete property

Parameters

property is an existing property. (The third form is legal only within a with statement.)

index is an integer representing the location of an element in an array.

Description

If the deletion succeeds, the delete operator sets the property or element to undefined. delete always returns undefined.


[Contents] [Previous] [Next] [Last]