⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ops.html

📁 javascript 1.5规范
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<ztablehead>Description</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1043874"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><ztablehead>Examples returning true<A HREF="#1050189"><SUP>1</SUP></A></ztablehead></B></FONT></TH>  </DIV></TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1043876"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Equal (<FONT FACE="courier, couriernew, monospaced size">==</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1043878"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the operands are equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1043880"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>3 == var1<br>"3" == var1<br>3 == '3'</zcodeline></FONT><P>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1043882"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Not equal (<FONT FACE="courier, couriernew, monospaced size">!=</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1043884"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the operands are not equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1043886"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>var1 != 4<br>var1 != "3"</zcodeline></FONT><P>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1049523"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Strict equal (<FONT FACE="courier, couriernew, monospaced size">===</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1049525"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the operands are equal and of the same type.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1049527"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>3 === var1</zcodeline></FONT><P>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1049529"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Strict not equal (<FONT FACE="courier, couriernew, monospaced size">!==</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1049531"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the operands are not equal and/or not of the same type.</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1049533"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>var1 !== "3"<br>3 !== '3'</zcodeline></FONT><P>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1043888"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Greater than (<FONT FACE="courier, couriernew, monospaced size">&gt;</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1043890"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the left operand is greater than the right operand. </ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1043892"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>var2 &gt; var1</zcodeline></FONT><P>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1043894"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Greater than or equal (<FONT FACE="courier, couriernew, monospaced size">&gt;=</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1043896"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the left operand is greater than or equal to the right operand. </ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1043898"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>var2 &gt;= var1<br>var1 &gt;= 3</zcodeline></FONT><P>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1043900"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Less than (<FONT FACE="courier, couriernew, monospaced size">&lt;</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1043902"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the left operand is less than the right operand. </ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1043904"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>var1 &lt; var2</zcodeline></FONT><P>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1043906"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Less than or equal (<FONT FACE="courier, couriernew, monospaced size">&lt;=</FONT>)</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1043908"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns true if the left operand is less than or equal to the right operand. </ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1043910"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>var1 &lt;= var2<br>var2 &lt;= 5</zcodeline></FONT><P>&nbsp;</TD>  </TR></TABLE><TABLE>  <TR>    <TD><A HREF="#1043874"><SUP>1</SUP></A><a name="1050189"> </a><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1">These examples assume that <FONT FACE="courier, couriernew, monospaced size">var1</FONT> has been assigned the value 3 and <FONT FACE="courier, couriernew, monospaced size">var2</FONT> has been assigned the value 4.</FONT><P></TD>  </TR></TABLE><P></FONT><P><P><BR><A NAME="1050908"> </A><A NAME="Using the Equality Operators"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead2>Using the Equality Operators</zhead2></FONT><BR><BR><A NAME="1050207"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The standard equality operators (== and !=) compare two operands without regard to their type. The strict equality operators (=== and !==) perform equality comparisons on operands of the same type. Use strict equality operators if the operands must be of a specific type as well as value or if the exact type of the operands is important. Otherwise, use the standard equality operators, which allow you to compare the identity of two operands even if they are not of the same type.</zparagraph></FONT><P><A NAME="1051096"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>When type conversion is needed, JavaScript converts <FONT FACE="courier, couriernew, monospaced size">String</FONT>, <FONT FACE="courier, couriernew, monospaced size">Number</FONT>, <FONT FACE="courier, couriernew, monospaced size">Boolean</FONT>, or <FONT FACE="courier, couriernew, monospaced size">Object</FONT> operands as follows.</zparagraph></FONT><P><ul><A NAME="1051097"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>When comparing a number and a string, the string is converted to a number value. JavaScript attempts to convert the string numeric literal to a <FONT FACE="courier, couriernew, monospaced size">Number</FONT> type value. First, a mathematical value is derived from the string numeric literal. Next, this value is rounded to nearest <FONT FACE="courier, couriernew, monospaced size">Number</FONT> type value.</zsmartlist1></FONT><P><A NAME="1051098"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>If one of the operands is <FONT FACE="courier, couriernew, monospaced size">Boolean</FONT>, the Boolean operand is converted to 1 if it is <FONT FACE="courier, couriernew, monospaced size">true</FONT> and +0 if it is <FONT FACE="courier, couriernew, monospaced size">false</FONT>.</zsmartlist1></FONT><P><A NAME="1051099"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>If an object is compared with a number or string, JavaScript attempts to return the default value for the object. Operators attempt to convert the object to a primitive value, a <FONT FACE="courier, couriernew, monospaced size">String</FONT> or <FONT FACE="courier, couriernew, monospaced size">Number</FONT> value, using the <FONT FACE="courier, couriernew, monospaced size">valueOf</FONT> and <FONT FACE="courier, couriernew, monospaced size">toString</FONT> methods of the objects. If this attempt to convert the object fails, a runtime error is generated.</zsmartlist1></FONT><P></ul><A NAME="1065532"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You cannot use the standard equality operator (<FONT FACE="courier, couriernew, monospaced size">==</FONT>) to compare instances of <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT>. Use the <A HREF="lcjsobj.html#1194386"  >JSObject.equals</A> method for such comparisons.</zparagraph></FONT><P><BR><A NAME="1050474"> </A><A NAME="Backward Compatibility"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><zrefheader>Backward Compatibility</zrefheader></B></FONT><BR><A NAME="1051242"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The behavior of the standard equality operators (== and !=) depends on the JavaScript version.</zparagraph></FONT><P><P><A NAME="1056739"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><zheadrunin>JavaScript 1.3 and earlier versions. </zheadrunin></B></FONT><A NAME="1056788"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>You can use either the standard equality operator (<FONT FACE="courier, couriernew, monospaced size">==</FONT>) or <A HREF="lcjsobj.html#1194386"  >JSObject.equals</A> to compare instances of <FONT FACE="courier, couriernew, monospaced size">JSObject</FONT>.</zparagraph></FONT><P><P><A NAME="1050483"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><zheadrunin>JavaScript 1.2. </zheadrunin></B></FONT><A NAME="1051334"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The standard equality operators (== and !=) do not perform a type conversion before the comparison is made. The strict equality operators (=== and !==) are unavailable.</zparagraph></FONT><P><P><A NAME="1050705"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><zheadrunin>JavaScript 1.1 and earlier versions. </zheadrunin></B></FONT><A NAME="1051338"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The standard equality operators (== and !=) perform a type conversion before the comparison is made. The strict equality operators (=== and !==) are unavailable.</zparagraph></FONT><P><BR><BR><A NAME="1042400"> </A><A NAME="Arithmetic Operators"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead1>Arithmetic Operators</zhead1><HR SIZE="2" NOSHADE></FONT><BR><A NAME="1042401"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/).<BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B></B></FONT><BR><BR>  <TR>    <TD VALIGN=TOP><P><A NAME="1061137"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1061139"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>JavaScript 1.0</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1061141"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>ECMA version</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1061143"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>ECMA-262</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zparagraph></FONT><P><A NAME="1061129"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>These operators work as they do in most other programming languages, except the / operator returns a floating-point division in JavaScript, not a truncated division as it does in languages such as C or Java. For example:</zparagraph></FONT><P><A NAME="1061117"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>1/2 //returns 0.5 in JavaScript<br>1/2 //returns 0 in Java</zcodeline></FONT><P><P><BR><A NAME="1042403"> </A><A NAME="% (Modulus)"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead2>% (Modulus)</zhead2></FONT><BR><BR><A NAME="1042406"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The modulus operator is used as follows:</zparagraph></FONT><P><A NAME="1042407"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline><I>var1</I> % <I>var2</I></zcodeline></FONT><P><A NAME="1042408"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The modulus operator returns the first operand modulo the second operand, that is, <FONT FACE="courier, couriernew, monospaced size">var1</FONT> modulo <FONT FACE="courier, couriernew, monospaced size">var2</FONT>, in the preceding statement, where <FONT FACE="courier, couriernew, monospaced size">var1</FONT> and <FONT FACE="courier, couriernew, monospaced size">var2</FONT> are variables. The modulo function is the integer remainder of dividing <FONT FACE="courier, couriernew, monospaced size">var1</FONT> by <FONT FACE="courier, couriernew, monospaced size">var2</FONT>. For example, 12 % 5 returns 2.</zparagraph></FONT><P><P><BR><A NAME="1042412"> </A><A NAME="++ (Increment)"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead2>++ (Increment)</zhead2></FONT><BR><BR><A NAME="1042415"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The increment operator is used as follows:</zparagraph></FONT><P><A NAME="1042416"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph><I>var</I><FONT FACE="courier, couriernew, monospaced size">++</FONT> or <FONT FACE="courier, couriernew, monospaced size">++</FONT><I>var</I></zparagraph></FONT><P><A NAME="1042417"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This operator increments (adds one to) its operand and returns a value. If used postfix, with operator after operand (for example, x++), then it returns the value before incrementing. If used prefix with operator before operand (for example, ++x), then it returns the value after incrementing.</zparagraph></FONT><P><A NAME="1042419"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, if x is three, then the statement <FONT FACE="courier, couriernew, monospaced size">y&nbsp;=&nbsp;x++ </FONT>sets <FONT FACE="courier, couriernew, monospaced size">y</FONT> to 3 and increments <FONT FACE="courier, couriernew, monospaced size">x</FONT> to 4. If <FONT FACE="courier, couriernew, monospaced size">x</FONT> is 3, then the statement <FONT FACE="courier, couriernew, monospaced size">y&nbsp;=&nbsp;++x </FONT>increments <FONT FACE="courier, couriernew, monospaced size">x</FONT> to 4 and sets <FONT FACE="courier, couriernew, monospaced size">y</FONT> to 4.</zparagraph></FONT><P><P><BR><A NAME="1042421"> </A><A NAME="-- (Decrement)"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead2>-- (Decrement)</zhead2></FONT><BR><BR><A NAME="1042424"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The decrement operator is used as follows:</zparagraph></FONT><P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -