Bitwise NOT
The bitwise NOT is represented by a tilde (~) and simply returns the one's complement of the number. Consider this example: let num1 = 25; // binary 00000000000000000000000000011001 let num2 = ~num1; // binary 11111111111111111111111111100110 console.log(num2); // -26 Here, the bitwise NOT operator is used on 25, producing -26 as the result. This is the effect of the bitwise NOT: it negates the number and subtracts 1. The same outcome is produced with the following code: let num1 = 25; let num2 = -num1 - 1; console.log(num2); // "-26" The bitwise operation is much faster than the math operator because it works at the very lowest level of numeric representation.Bitwise AND Operator
The bitwise AND operator is indicated by the ampersand character (&) and works on two values. The bitwise AND operator lines up the bits in each number and use the rules in the following truth table, performs an AND operation between the two bits in the same position.
Bit From First Number | Bit From Second Number | Result |
---|---|---|
1 | 1 | 1 |
1 | 0 | 0 |
0 | 1 | 0 |
0 | 0 | 0 |
Bit From First Number | Bit From Second Number | Result |
---|---|---|
1 | 1 | 1 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 0 | 0 |
Bit From First Number | Bit From Second Number | Result |
---|---|---|
1 | 1 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
0 | 0 | 0 |
OPERAND 1 | OPERAND 2 | RESULT |
---|---|---|
true | true | true |
true | false | false |
false | true | false |
false | false | false |
OPERAND 1 | OPERAND 2 | RESULT |
---|---|---|
true | true | true |
true | false | true |
false | true | true |
false | false | false |
x | typeof x |
---|---|
undefined | "undefined" |
null | "object" |
true or false | "boolean" |
any number or NaN | "number" |
any BigInt | "bigint" |
any string | "string" |
any symbol | "symbol" |
any function | "function" |
any non function object | "object" |
Format | Example |
---|---|
month/date/year | 5/24/2020 |
month_name date, year | May 24, 2020 |
day_of_week month_name date year hours:minutes:seconds time_zone | Tue May 23 2020 00:00:00 GMT-0700 |
ISO 8601 extended format YYYY-MM-DDTHH:mm:ss.sssZ | 2020-05-23T00:00:00 |
Method | Description |
---|---|
toDateString() toTimeString() toLocaleDateString() toLocaleTimeString() toUTCString() | Displays the date's day of the week, month, day of the month, and year in an implementation-specific format. Displays the date's hours, minutes, seconds, and time zone in an implementation-specific format. Displays the date's day of the week, month, day of the month, and year in an implementation and locale-specific format. Displays the date's hours, minutes, and seconds in an implementation-specific format. Displays the complete UTC date in an implementation-specific format. |
Method | Description |
---|---|
getTime() | Returns the milliseconds representation of the date; same as valueOf(). |
setTime(milliseconds) | Sets the milliseconds representation of the date, thus changing the entire date. |
getFullYear() | Returns the four-digit year (2019 instead of just 19). |
getUTCFullYear() | Returns the four-digit year of the UTC date value. |
setFullYear(year) | Sets the year of the date. The year must be given with four digits (2019 instead of just 19). |
setUTCFullYear(year) | Sets the year of the UTC date. The year must be given with four digits (2019 instead of just 19). |
getMonth() | Returns the month of the date, where 0 represents January and 11 represents December. |
getUTCMonth() | Returns the month of the UTC date, where 0 represents January and 11 represents December. |
setMonth(month) | Sets the month of the date, which is any number 0 or greater. Numbers greater than 11 add years. |
setUTCMonth(month) | Sets the month of the UTC date, which is any number 0 or greater. Numbers greater than 11 add years. |
getDate() | Returns the day of the month (1 through 31) for the date. |
getUTCDate() | Returns the day of the month (1 through 31) for the UTC date. |
setDate(date) | Sets the day of the month for the date. If the date is greater than the number of days in the month, the month value also gets increased. |
setUTCDate(date) | Sets the day of the month for the UTC date. If the date is greater than the number of days in the month, the month value also gets increased. |
getDay() | Returns the date's day of the week as a number (where 0 represents Sunday and 6 represents Saturday). |
getUTCDay() | Returns the UTC date's day of the week as a number (where 0 represents Sunday and 6 represents Saturday). |
getHours() | Returns the date's hours as a number between 0 and 23. |
getUTCHours() | Returns the UTC date's hours as a number between 0 and 23. |
setHours (hours) | Sets the date's hours. Setting the hours to a number greater than 23 also increments the day of the month. |
setUTCHours(hours) | Sets the UTC date's hours. Setting the hours to a number greater than 23 also increments the day of the month. |
getMinutes() | Returns the date's minutes as a number between 0 and 59. |
getUTCMinutes() | Returns the UTC date's minutes as a number between 0 and 59. |
setMinutes(minutes) | Sets the date's minutes. Setting the minutes to a number greater than 59 also increments the hour. |
setUTCMinutes(minutes) | Sets the UTC date's minutes. Setting the minutes to a number greater than 59 also increments the hour. |
getSeconds() | Returns the date's seconds as a number between 0 and 59. |
getUTCSeconds() | Returns the UTC date's seconds as a number between 0 and 59. |
setSeconds(seconds) | Sets the date's seconds. Setting the seconds to a number greater than 59 also increments the minutes. |
setUTCSeconds(seconds) | Sets the UTC date's seconds. Setting the seconds to a number greater than 59 also increments the minutes. |
getMilliseconds() | Returns the date's milliseconds. |
getUTCMilliseconds() | Returns the UTC date's milliseconds. |
setMilliseconds(milliseconds) | Sets the date's milliseconds. |
setUTCMilliseconds (milliseconds) | Sets the UTC date's milliseconds. |
getTimezoneOffset() | Returns the number of minutes that the local time zone is offset from UTC. For example, Eastern Standard Time returns 300. This value changes when an area goes into Daylight Saving Time. |
Flag | Description |
---|---|
g | Indicates global mode, meaning the pattern will be applied to all of the string instead of stopping after the first match is found. |
i | Indicates case-insensitive mode, meaning the case of the pattern and the string are ignored when determining matches. |
m | Indicates multiline mode, meaning the pattern will continue looking for matches after reaching the end of one line of text. |
y | Indicates sticky mode, meaning the pattern will only look at the string contents beginning at lastIndex. |
u | Indicates Unicode mode is enabled. |
Literal Pattern | String Equivalent |
---|---|
/\[bc\]at/ | "\\[bc\\]at" |
/\.at/ | "\\.at" |
/name\/age/ | "name\\/age" |
/\d.\d{1,2}/ | "\\d.\\d{1,2}" |
/\w\\hello\\123/ | "\\w\\\\hello\\\\123" |
Property | Type | Description |
---|---|---|
global | Boolean | indicating whether the g flag has been set. |
ignoreCase | Boolean | indicating whether the i flag has been set. |
unicode | Boolean | indicating whether the u flag has been set. |
sticky | Boolean | indicating whether the y flag has been set. |
lastIndex | integer | indicating the character position where the next match will be attempted in the source string. This value always begins as 0. |
multiline | Boolean | indicating whether the m flag has been set. |
source | string | source of the regular expression. This is always returned as if specified in literal form (without opening and closing slashes) rather than a string pattern as passed into the constructor. |
flags | string | flags of the regular expression. This is always returned as if specified in literal form (without opening and closing slashes) rather than a string pattern as passed into the constructor. |
Verbose Name | Short Name | Description |
---|---|---|
input | $_ | The last string matched against. |
lastMatch | $& | The last matched text. |
lastParen | $+ | The last matched capturing group. |
leftContext | $` | The text that appears in the input string prior to lastMatch. |
rightContext | $' | The text that appears in the input string after lastMatch. |
\n
| Yes | Yes | Yes | Yes | Yes | Yes |
?!
| Yes | Yes | Yes | Yes | Yes | Yes |
?=
| Yes | Yes | Yes | Yes | Yes | Yes |
[^0-9]
| Yes | Yes | Yes | Yes | Yes | Yes |
\0
| Yes | Yes | Yes | Yes | Yes | Yes |
{X}
| Yes | Yes | Yes | Yes | Yes | Yes |
{X,}
| Yes | Yes | Yes | Yes | Yes | Yes |
{X,Y}
| Yes | Yes | Yes | Yes | Yes | Yes |
\xxx
| Yes | Yes | Yes | Yes | Yes | Yes |
+
| Yes | Yes | Yes | Yes | Yes | Yes |
\t
| Yes | Yes | Yes | Yes | Yes | Yes |
\udddd
| Yes | Yes | Yes | Yes | Yes | Yes |
\v
| Yes | Yes | Yes | Yes | Yes | Yes |
\S
| Yes | Yes | Yes | Yes | Yes | Yes |
\s
| Yes | Yes | Yes | Yes | Yes | Yes |
\W
| Yes | Yes | Yes | Yes | Yes | Yes |
\w
| Yes | Yes | Yes | Yes | Yes | Yes |
(x|y)
| Yes | Yes | Yes | Yes | Yes | Yes |
*
| Yes | Yes | Yes | Yes | Yes | Yes |
?
| Yes | Yes | Yes | Yes | Yes | Yes |
Property | Description |
---|---|
undefined | The special value undefined |
NaN | The special value NaN |
Infinity | The special value Infinity |
Object | Constructor for Object |
Array | Constructor for Array |
Function | Constructor for Function |
Boolean | Constructor for Boolean |
String | Constructor for String |
Number | Constructor for Number |
Date | Constructor for Date |
RegExp | Constructor for RegExp |
Symbol | Pseudo-constructor for Symbol |
Error | Constructor for Error |
EvalError | Constructor for EvalError |
RangeError | Constructor for RangeError |
ReferenceError | Constructor for ReferenceError |
SyntaxError | Constructor for SyntaxError |
TypeError | Constructor for TypeError |
URIError | Constructor for URIError |
Property | Description |
---|---|
Math.E | The value of e, the base of the natural logarithms |
Math.LN10 | The natural logarithm of 10 |
Math.LN2 | The natural logarithm of 2 |
Math.LOG2E | The base 2 logarithm of e |
Math.LOG10E | The base 10 logarithm of e |
Math.PI | The value of p |
Math.SQRT1_2 | The square root of 0.5 |
Math.SQRT2 | The square root of 2 |
Method | Description |
---|---|
Math.abs(x) | Returns the absolute value of x |
Math.exp(x) | Returns Math.E raised to the power of x |
Math.expm1(x) | Equivalent to Math.exp(x) - 1 |
Math.log(x) | Returns the natural logarithm of x |
Math.log1p(x) | Equivalent to 1 + Math.log(x) |
Math.pow(x, power) | Returns x raised to the power of power |
Math.pow (...numbers) | Returns the square root of the sum of the squares of each number in numbers |
Math.clz32 (x) | Returns the number of leading zeroes of a 32-bit integer x |
Math.sign(x) | Returns 1, 0, -0, or -1 indicating the sign of x |
Math.trunc(x) | Returns the integer component of x, removing any decimals |
Math.sqrt(x) | Returns the square root of x |
Math.cbrt(x) | Returns the cubic root of x |
Math.acos(x) | Returns the arc cosine of x |
Math.acosh(x) | Returns the hyperbolic arc cosine of x |
Math.asin(x ) | Returns the arc sine of x |
Math.asin(x ) | Returns the hyperbolic arc sine of x |
Math.atan(x ) | Returns the arc tangent of x |
Math.atanh(x ) | Returns the hyperbolic arc tangent of x |
Math.atan2(y, x ) | Returns the arc tangent of y/x |
Math.cos(x ) | Returns the cosine of x |
Math.sin(x ) | Returns the sine of x |
Math.tan(x ) | Returns the tangent of x |
Method | Description |
---|---|
Math.ceil() | rounds numbers up to the nearest integer value. |
Math.floor() | always rounds numbers down to the nearest integer value. |
Math.round() | rounds up if the number is at least halfway to the next integer value (0.5 or higher) and rounds down if not. |
Math.fround() | returns the nearest single precision (32 bits) floating point representation of the number. |