All these functions are modal, they pause the code execution and prevent the visitor from interacting… Assignments
There is a simple assignment: a = b and combined ones like a *= 2.… Parameters can have default values: function sum(a = 1, b = 2) {...}.
The mini-window with the message is called a modal… The word “modal” means that the visitor can’t interact with the rest of the page, press other buttons… accepts two arguments:
It shows a modal… All these methods are modal: they pause script execution and don’t allow the visitor to interact with… There are two limitations shared by all the methods above:
The exact location of the modal window is
For example, to calculate pow(2, 4) the recursive variant does these steps:
pow(2, 4) = 2 * pow(2, 3… )
pow(2, 3) = 2 * pow(2, 2)
pow(2, 2) = 2 * pow(2, 1)
pow(2, 1) = 2
So, the recursion reduces a function… Here’s the context stack when we entered the subcall pow(2, 2):
Context: { x: 2, n: 2, at line… n: 1, at line 1 }
pow(2, 1)
Context: { x: 2, n: 2, at line 5 }
pow(2, 2)… pow(2, 2)
Context: { x: 2, n: 3, at line 5 }
pow(2, 3)
The execution of pow(2, 2) is
Otherwise, if the first digit is 2, then the next must be [0-3].… (no other first digit is allowed)
We can write both variants in a regexp using alternation: [01]\d|2[… If we glue hours and minutes together, we get the pattern: [01]\d|2[0-3]:[0-5]\d.… The alternation | now happens to be between [01]\d and 2[0-3]:[0-5]\d.… Let’s correct that by enclosing “hours” into parentheses: ([01]\d|2[0-3]):[0-5]\d.
There may be 2, 3, 4 or more.… In the demo above they are labeled: 1, 2, 3.
Build segments between control points 1 → 2 → 3.… 2 → 3, 3 → 4.… There will be N-2 segments.
Repeat step 2 until there is only one point.… 0 + 2(1−t)t * 0.5 + t2 * 1 = (1-t)t + t2 = t
y = (1−t)2 * 0 + 2(1−t)t * 1 + t2 * 0 = 2(1-t)t = –2t2 +
operand is 2.… The 2 gets concatenated to '1', so it’s like '1' + 2 = "12" and "12" + 2 = "… For example, write (1 + 2) * 2.
There are many operators in JavaScript.… So, the alert shows 2.… It’s like (a = 1 + 2), 3 + 4.
To do so legally, a website shows a modal “splash screen” for newcomers and requires them to agree to… No one likes to see such “must-click” modal splash screens instead of the content.
Surrogate pairs.All frequently used characters have 2-byte codes (4 hex digits).… Initially, JavaScript was based on UTF-16 encoding that only allowed 2 bytes per character.… But 2 bytes only allow 65536 combinations and that’s not enough for every possible symbol of Unicode.… So rare symbols that require more than 2 bytes are encoded with a pair of 2-byte characters called “a… As a side effect, the length of such symbols is 2:
Most characters are encoded with 2 bytes, but that allows to represent at most 65536 characters.… are the Unicode values of some characters:
Character
Unicode
Bytes count in Unicode
a
0x0061
2… ≈
0x2248
2
𝒳
0x1d4b3
4
𝒴
0x1d4b4
4
😄
0x1f604
4
So characters like a and ≈ occupy 2 bytes… The point is that length treats 4 bytes as two 2-byte characters.… By default, regular expressions also treat 4-byte “long characters” as a pair of 2-byte ones.
second (*),
Then the .then handler is called (**), which in turn creates a new promise (resolved with 2… As the result is passed along the chain of handlers, we can see a sequence of alert calls: 1 → 2 → 4.… That handler is in the line (**), it shows 2 and does the same thing.… So the output is the same as in the previous example: 1 → 2 → 4, but now with 1 second delay between… In the example above resolve(2) is called after 1 second (**).
base=2 is mostly for debugging bitwise operations, digits can be 0 or 1.… several built-in functions for rounding:
Math.floor
Rounds down: 3.1 becomes 3, and -1.1 becomes -2.… -1
-1
-1
-1.5
-2
-1
-1
-1
-1.6
-2
-1
-2
-1
These functions cover all of the possible ways to deal… For instance, we have 1.2345 and want to round it to 2 digits, getting only 1.23.… It ensures that it has 2 digits after the decimal point.
…But please note: the example above shows 1, then 2, and that’s all. It doesn’t show 3!… It starts the execution and returns the result of the first yield "2+2=?".… For instance, here the yield of "2 + 2 = ?… The error, thrown into the generator at line (2)… The current line of the calling code is the line with generator.throw, labelled as (2).
For example, the pattern \b\d\d\b looks for standalone 2-digit numbers.… In other words, it looks for 2-digit numbers that are surrounded by characters different from \w, such
The multiplication obj * 2… first converts the object to primitive (that’s a string "2").… Then "2" * 2 becomes 2 * 2 (the string is converted to number).
For compatibility, 2 digits are also accepted and considered 19xx, e.g. 98 is the same as 1998 here,… It returns 2-digit year sometimes. Please never use it. There is getFullYear() for the year.… Let’s say we need to increase the date “28 Feb 2016” by 2 days.… It may be “2 Mar” or “1 Mar” in case of a leap-year. We don’t need to think about it.… Just add 2 days.
They both call func with arguments 1, 2… So when worker.slow(2) is executed, the wrapper gets 2 as an argument and this=worker (it’s the object… is not yet cached, func.call(this, x) passes the current this (=worker) and the current argument (=2)… Append glue and this[2].
…Do so until this.length items are glued.
Return result.
Solution 2: bind.Functions provide a built-in method bind that allows to fix this.… The call to mul.bind(null, 2)… creates a new function double that passes calls to mul, fixing null as the context and 2 as the first
We can open it with version 2 and perform the upgrade like this:… And it can’t be both version 1 and 2.… from 2 to 3, from 3 to 4 etc.… by step, for every intermediate version (2 to 3, then 3 to 4).… Get the store object using transaction.objectStore(name), at (2).
Indents.There are two types of indents:
Horizontal indents: 2 or 4 spaces.… A horizontal indentation is made using either 2 or 4 spaces or the horizontal tab symbol (key Tab).… Option 1:
Option 2:
Here space = 2 tells JavaScript to show nested objects on multiple lines, with indentation of 2 spaces… Now let’s add a custom toJSON for our object room (2):
state
event.button
Left button (primary)
0
Middle button (auxiliary)
1
Right button (secondary)
2… (forward)
4
Most mouse devices only have the left and right buttons, so possible values are 0 or 2.… non-standard way of getting a button, with possible values:
event.which == 1 – left button,
event.which == 2
Similar to that, \2 would mean the contents of the second group, \3 – the 3rd group, and so on.
We can put anything in there: a variable like name or an arithmetical expression like 1 + 2 or something… Usually, such parentheses contain a mathematical expression, such as (2 + 2), but here they contain only
Uint16Array – treats every 2 bytes as an integer, with possible values from 0 to 65535.… binary data in an ArrayBuffer of 16 bytes can be interpreted as 16 “tiny numbers”, or 8 bigger numbers (2… bytes each), or 4 even bigger (4 bytes each), or 2 floating-point values with high precision (8 bytes
In the code above:
We load 1.js, then if there’s no error…
We load 2.… loadScript('2.js', function(error, script) {
if (error) {
handleError(error);
} else
Parentheses can be omitted, if there’s only a single argument, e.g. n => n*2.
The order became 1, 15, 2. Incorrect. But why?
The items are sorted as strings by default.… For strings, lexicographic ordering is applied and indeed "2" > "15".… The function passed to reduce uses only 2… On the second run, sum = 1, we add the second array element (2) to it and return.… call on the next array element:
sum
current
result
the first call
0
1
1
the second call
1
2
:
offsetWidth = 390 – the outer width, can be calculated as inner CSS-width (300px) plus paddings (2… * 20px) and borders (2 * 25px).
offsetHeight = 290 – the outer height.… so it’s exactly the sum of what’s inside the borders: CSS-height 200px plus top and bottom paddings (2
is: if we have two elements, the first has tabindex="1", and the second has tabindex="2&… The order is like this: 1 - 2
That’s why (2) null == 0 is false.… We get these results because:
Comparisons (1) and (2) return false because undefined gets converted
For instance, the Promise.all below settles after 3 seconds, and then its result is an array [1, 2, 3… For instance, here the results are [1, 2, 3]:
Full example.Here’s the server that sends messages with 1, 2,… connection state: either EventSource.CONNECTING (=0), EventSource.OPEN (=1) or EventSource.CLOSED (=2)
The first number \d+ has 7 digits, and then a number of 2 digits:… The first number has 6 digits, and then 2… Here \2
The output order is: 1 → nested → 2.… The output order becomes: 1 → 2 → nested.
part of the string before the match
$'
inserts a part of the string after the match
$n
if n is a 1-2… parentheses, so the replacement function is called with 5 arguments: the first is the full match, then 2
The ending point also has <p> as the parent node, but 2 as the offset (it specifies the range up… So we can set it as range.setEnd(p, 2).
Here’s the demo.… We need to create a range, that:
starts from position 2 in <p> first child (taking all but two… startOffset – node and offset of the start,
in the example above: first text node inside <p> and 2.
Wrote some code, testing: f(1) works, but f(2) doesn’t work. We fix the code and now f(2) works.… Here it checks that the result of pow(2, 3) equals 8.
The following example will show the message every 2 seconds.… The actual interval between alerts will be shorter than 2 seconds.
At index 2: the contents of the second parentheses.… Then in result[2] goes the group from the second opening paren ([a-z]+) – tag name, then in result[3]
Then this wrapper is called with 2 as an argument, and it passes the call to the original sum.
This method must return the object with next() method returning a promise (2).… page=2. It’s generated by GitHub itself.
Here’s the picture, taken from the specification, of the capturing (1), target (2) and bubbling (3) phases… event (the one that has the handler on it)
event.eventPhase – the current phase (capturing=1, target=2,
The typical output:
[1] initial readyState:loading
[2] readyState:interactive
[2] DOMContentLoaded
[
For example, here the menu item is inserted dynamically after 1 second, and the title changes after 2… Please note: there’s no slotchange event after 2 seconds, when the content of slot="title"
For now, just remember the result of running the code: it shows Hello, then 1, then 2.
part of the string before the match
$'
inserts a part of the string after the match
$n
if n is a 1-2
So .at(-1) means the last character, and .at(-2) is the one before it, etc.… To look for the next occurrence, let’s start the search from position 2:
Only first 50 results are shown.