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

📄 ops.html

📁 javascript 1.5规范
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<A NAME="1042425"> </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="1042426"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>This operator decrements (subtracts one from) its operand and returns a value. If used postfix (for example, x--), then it returns the value before decrementing. If used prefix (for example, --x), then it returns the value after decrementing.</zparagraph></FONT><P><A NAME="1042428"> </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 decrements <FONT FACE="courier, couriernew, monospaced size">x</FONT> to 2. 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> decrements <FONT FACE="courier, couriernew, monospaced size">x</FONT> to 2 and sets <FONT FACE="courier, couriernew, monospaced size">y</FONT> to 2.</zparagraph></FONT><P><P><BR><A NAME="1042430"> </A><A NAME="- (Unary Negation)"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead2>- (Unary Negation)</zhead2></FONT><BR><BR><A NAME="1042433"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The unary negation operator precedes its operand and negates it. For example, <FONT FACE="courier, couriernew, monospaced size">y&nbsp;=&nbsp;-x</FONT> negates the value of <FONT FACE="courier, couriernew, monospaced size">x</FONT> and assigns that to <FONT FACE="courier, couriernew, monospaced size">y</FONT>; that is, if <FONT FACE="courier, couriernew, monospaced size">x</FONT> were 3, <FONT FACE="courier, couriernew, monospaced size">y</FONT> would get the value -3 and <FONT FACE="courier, couriernew, monospaced size">x</FONT> would retain the value 3.</zparagraph></FONT><P><BR><BR><A NAME="1042437"> </A><A NAME="Bitwise Operators"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead1>Bitwise Operators</zhead1><HR SIZE="2" NOSHADE></FONT><BR><A NAME="1042438"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Bitwise operators treat their operands as a set of 32 bits (zeros and ones), rather than as decimal, hexadecimal, or octal numbers. For example, the decimal number nine has a binary representation of 1001. Bitwise operators perform their operations on such binary representations, but they return standard JavaScript numerical values.</zparagraph></FONT><P><A NAME="1042498"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>The following table summarizes JavaScript's bitwise operators:</zparagraph></FONT><P><P><A NAME="1052986"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><BR><P><TABLE WIDTH="90%" BORDER="1" CELLPADDING="5" CELLSPACING="0">  <CAPTION></CAPTION><P><FONT FACE=""><B><A NAME="1042441"> </A><A NAME="Bitwise operators"> </A><ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><ztablecaption>Table 5.4&#32;&nbsp&nbsp Bitwise operators</ztablecaption></B></FONT></B></FONT><BR><BR>  <TR BGCOLOR="#CCCCCC" ALIGN=LEFT VALIGN=TOP>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1042447"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><ztablehead>Operator</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1042449"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><ztablehead>Usage</ztablehead></B></FONT></TH>    <TH VALIGN=TOP ALIGN=LEFT><A NAME="1042451"> </A><P ALIGN="LEFT"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B><ztablehead>Description</ztablehead></B></FONT></TH>  </DIV></TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1042453"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Bitwise AND</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1042456"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>a &amp; b</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1061174"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns a one in each bit position for which the corresponding bits of both operands are ones.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1042460"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Bitwise OR</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1042463"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>a | b</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1061188"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns a one in each bit position for which the corresponding bits of either or both operands are ones.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1042467"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Bitwise XOR</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1042470"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>a ^ b</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1061194"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Returns a one in each bit position for which the corresponding bits of either but not both operands are ones.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1042474"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Bitwise NOT</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1042477"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>~ a</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1042479"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Inverts the bits of its operand.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1042481"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Left shift</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1042483"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>a &lt;&lt; b</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1042485"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Shifts <FONT FACE="courier, couriernew, monospaced size">a</FONT> in binary representation <FONT FACE="courier, couriernew, monospaced size">b</FONT> bits to left, shifting in zeros from the right.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1042487"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Sign-propagating right shift</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1042489"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>a &gt;&gt; b</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1042491"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Shifts <FONT FACE="courier, couriernew, monospaced size">a</FONT> in binary representation <FONT FACE="courier, couriernew, monospaced size">b</FONT> bits to right, discarding bits shifted off.</ztabletext></FONT>&nbsp;</TD>  </TR>  <TR>    <TD VALIGN=TOP><P><A NAME="1042493"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Zero-fill right shift</ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><A NAME="1042495"></A><FONT FACE="courier, couriernew, monospaced size" SIZE="-1"><zcodeline>a &gt;&gt;&gt; b</zcodeline></FONT><P>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1042497"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>Shifts <FONT FACE="courier, couriernew, monospaced size">a</FONT> in binary representation <FONT FACE="courier, couriernew, monospaced size">b</FONT> bits to the right, discarding bits shifted off, and shifting in zeros from the left.</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></FONT><P><P><BR><A NAME="1042500"> </A><A NAME="Bitwise Logical Operators<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="1044145"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1044147"> </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="1053136"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>ECMA version</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1053138"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>ECMA-262</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P>"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="4"><zhead2>Bitwise Logical Operators<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="1044145"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1044147"> </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="1053136"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>ECMA version</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1053138"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>ECMA-262</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE><P></zhead2></FONT><BR><BR><A NAME="1042503"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>Conceptually, the bitwise logical operators work as follows:</zparagraph></FONT><P><ul><A NAME="1042504"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>The operands are converted to thirty-two-bit integers and expressed by a series of bits (zeros and ones).</zsmartlist1></FONT><P><A NAME="1042505"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>Each bit in the first operand is paired with the corresponding bit in the second operand: first bit to first bit, second bit to second bit, and so on.</zsmartlist1></FONT><P><A NAME="1042506"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>The operator is applied to each pair of bits, and the result is constructed bitwise.</zsmartlist1></FONT><P></ul><A NAME="1042507"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2"><zparagraph>For example, the binary representation of nine is 1001, and the binary representation of fifteen is 1111. So, when the bitwise operators are applied to these values, the results are as follows:</zparagraph></FONT><P><ul><A NAME="1042508"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>15 &amp; 9 yields 9 (1111 &amp; 1001 = 1001)</zsmartlist1></FONT><P><A NAME="1042509"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>15 | 9 yields 15 (1111 | 1001 = 1111)</zsmartlist1></FONT><P><A NAME="1042510"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><B>  <li></B><zsmartlist1>15 ^ 9 yields 6 (1111 ^ 1001 = 0110)</zsmartlist1></FONT><P></ul><P><BR><A NAME="1042512"> </A><A NAME="Bitwise Shift Operators<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="1044173"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>Implemented in</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1044175"> </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="1053141"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext><I>ECMA version</I></ztabletext></FONT>&nbsp;</TD>    <TD VALIGN=TOP><P><A NAME="1053143"> </A><FONT FACE="Arial, Helvetica, sans-serif" SIZE="-1"><ztabletext>ECMA-262</ztabletext></FONT>&nbsp;</TD>  </TR></TABLE>

⌨️ 快捷键说明

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