Math.trunc(n) is a function that “cuts off” the decimal part of a number, e.g Math.trunc(1.23) returns 1.… Good resources that show the current state of support for various features:
https://compat-table.github.io
In contrast, objects are used to store keyed collections of various data and more complex entities.… But if we run the code, we see a totally different picture:
USA (1) goes first
then Switzerland (41)… So we see 1, 41, 44, 49.
Integer properties? What’s that?… And they extend it in various ways.
Objects in JavaScript are very powerful.
style rules, manipulations with them, and their binding to documents, see https://www.w3.org/TR/cssom-1/… HTML specification
Describes the HTML language (e.g. tags) and also the BOM (browser object model) – various
For example, here 1+2 results in 3, while the function call hello("debugger") returns nothing… That’s useful when we have many breakpoints in various files.… Oh, and also you can click at various places of dev tools and just see what’s showing up.
So that obj[1] is the same as obj["1"], and obj[true] is the same as obj["true"].… symbols.There exist many “system” symbols that JavaScript uses internally, and we can use them to fine-tune various
In this article we’ll cover various methods that work with regexps in-depth.
str.match(regexp).The method… str.search(regexp).The method str.search(regexp) returns the position of the first match or -1… part of the string before the match
$'
inserts a part of the string after the match
$n
if n is a 1-
Please note: in the line (1)… widespread technique: a function handles low-level exceptions and creates higher-level errors instead of various
We can use this property to react differently on various pointer types.… Where unsupported, e.g. for a mouse, it’s always 1.
height – the height of the area where the pointer… Where unsupported, it’s always 1.
pressure – the pressure of the pointer tip, in range from 0 to 1.
Wrote some code, testing: f(1) works, but f(2) doesn’t work. We fix the code and now f(2) works.… But we forgot to re-test f(1). That may lead to an error.
That’s very typical.… They run our functions in various ways and compare results with the expected.
Let’s cover various events that accompany data updates.… A user may switch between various applications, copy/paste different things, and a browser page shouldn
There are various ways to solve this problem such as func.bind().
In the demo above they are labeled: 1, 2, 3.
Build segments between control points 1 → 2 → 3.… The formula for a 2-points curve:
P = (1-t)P1 + tP2
For 3 control points:
P = (1−t)2P1 + 2(1−t)tP2… + t2P3
For 4 control points:
P = (1−t)3P1 + 3(1−t)2tP2 +3(1−t)t2P3 + t3P4
These are vector equations… For instance, if control points are (0,0), (0.5, 1) and (1, 0), the equations become:
x = (1−t)2 *… 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 +
architecture
Provide a high-level overview of components, how they interact, what’s the control flow in various
\1.… Further in the pattern \1 means “find the same text as in the first group”, exactly the same quote in… Don’t mess up: in the pattern \1, in the replacement: $1
In the replacement string we use… a dollar sign: $1, while in the pattern – a backslash \1.
pow(2, 1).The process repeats: a new subcall is made at line 5, now with arguments x=2, n=1.… at line 1 }
pow(2, 1)
Context: { x: 2, n: 2, at line 5 }
pow(2, 2)
Context… pow(2, 1).… The exit.During the execution of pow(2, 1), unlike before, the condition n == 1 is truthy, so the first… It has the result of the subcall pow(2, 1), so it also can finish the evaluation of x * pow(x, n - 1)
-(253-1), as we mentioned earlier in the chapter Data types.… Math.ceil
Rounds up: 3.1 becomes 4, and -1.1 becomes -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… It is one divided by ten 1/10, one-tenth.… A few examples:
Math.random()
Returns a random number from 0 to 1 (not including 1).
The x axis is the time: 0 – the start, 1 – the end of transition-duration.… That can be specified by the curve cubic-bezier(0, 0, 1, 1).… The linear is a shorthand for cubic-bezier(0, 0, 1, 1) – a straight line, which we described above.… The y is out of the “standard” range 0..1.… That is, the animation starts immediately and takes 1 step.
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.… Both of these statements do the same thing: increase counter by 1.
Is there any difference?… So, the alert shows 1.… It’s like (a = 1 + 2), 3 + 4.
Here +a gives 1,… that’s compared with b + 1 in case, and the corresponding code is executed.… For 0, 1,
Here the flow is:
The initial promise resolves in 1 second (*),
Then the .then handler is called (**… As the result is passed along the chain of handlers, we can see a sequence of alert calls: 1 → 2 → 4.… So in the code above all alert show the same: 1.… 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 (**).
Response provides multiple promise-based methods to access the body in various formats:
response.text
Starting from the index 1 it removed 1 element.… The value of -1 is returned if nothing is found.… So the function result is 1.… On the second run, sum = 1, we add the second array element (2) to it and return.… 1
the second call
1
2
3
the third call
3
3
6
the fourth call
6
4
10
the fifth call
10
5
15
BigInt.In JavaScript, the “number” type cannot safely represent integer values larger than (253-1) (that… ’s 9007199254740991), or less than -(253-1) for negatives.… store larger integers (up to 1.7976931348623157 * 10308), but outside of the safe integer range ±(253-1)… For most purposes ±(253-1) range is quite enough, but sometimes we need the entire range of really big… We can put anything in there: a variable like name or an arithmetical expression like 1 + 2 or something
new Date(milliseconds)
Create a Date object with the time equal to number of milliseconds (1/… The date parameter is actually the day of month, if absent then 1 is assumed.… instance:
The maximal precision is 1… ms (1/1000 sec):… It may be “2 Mar” or “1 Mar” in case of a leap-year. We don’t need to think about it.
To be precise, there are 2n-1, where n is the length of the sequence.… =(\w+))\1. Of course, we could take another pattern instead of \w.… Then the engine will memorize their contents
…And allow us to reference it in the pattern as \1.… That is: we look ahead – and if there’s a word \w+, then match it as \1.
Why?… =(\w+))\1 instead of \w, when we need to forbid backtracking for + after it.
That is: if we have two elements, the first has tabindex="1", and the second has tabindex=&… The switch order is: elements with tabindex from 1 and above go first (in the tabindex order), and then… That is, when we switch elements, elements with tabindex=0 go after elements with tabindex ≥ 1.… tabindex="-1" allows only programmatic focusing on an element.… The order is like this: 1
A number is a sequence of 1 or more digits \d.… So the regexp is \d{1,}:… Shorthands.There are shorthands for most used quantifiers:
+
Means “one or more”, the same as {1,
Sleep until a task appears, then go to 1.… Use-case 1: splitting CPU-hungry tasks.Let’s say we have a CPU-hungry task.… count does a part of the job (*), and then re-schedules itself (**) if needed:
First run counts: i=1.… queued and then executes when part 1 finished, before the next part.… Go to step 1.
To schedule a new macrotask:
Use zero delayed setTimeout(f).
Some programming languages allow the use of negative indexes for the same purpose, like fruits[-1].… We can explicitly calculate the last element index and then access it: fruits[fruits.length - 1].… Both fruits.pop() and fruits.at(-1)… Move all elements to the left, renumber them from the index 1 to 0, from 2 to 1 and so on.… becomes "1" and [1,2] becomes "1,2".
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]:… For instance, here the result will be 1:… For instance, here the result will be 1:
instance, \d\s\w means a “digit” followed by a “space character” followed by a “wordly character”, such as 1… For us strings 1-5 and 1 - 5 are nearly identical.
Numeric conversion rules:
Value
Becomes…
undefined
NaN
null
0
true and false
1… The conversion follows the rules:
Value
Becomes…
undefined
NaN
null
0
true / false
1 / 0
know, JavaScript strings are based on Unicode: each character is represented by a byte sequence of 1-… \u{X…XXXXXX}
X…XXXXXX must be a hexadecimal value of 1 to 6 bytes between 0 and 10FFFF (the highest code… That said, if we take from position 1
like CSS-property transition-timing-function that gets the fraction of time that passed (0 at start, 1… The value progress=0 denotes the beginning animation state, and progress=1 – the end state.… Gets a time fraction from 0 to 1, returns the animation progress, usually from 0 to 1.
draw – the function
For the start, let’s find the price from the string like 1 turkey costs 30€.… In our string that exactly matches the number 1.
For boolean values, true becomes 1… That’s why (3) null >= 0 is true and (1) null > 0 is false.… We get these results because:
Comparisons (1) and (2) return false because undefined gets converted
There are three variants of type conversion, that happen in various situations.
suitable for users that are accessing for the first time and have no database, and also for version 1,… Let’s say:
A visitor opened our site in a browser tab, with database version 1.… So there’s a tab with an open connection to DB version 1, while the second one attempts to update it… And it can’t be both version 1 and 2.… To perform the update to version 2, all connections to version 1 must be closed, including the one in
On the teststand below, all mouse events are logged, and if there is more than a 1 second delay between… event.button are:
Button state
event.button
Left button (primary)
0
Middle button (auxiliary)
1… property that’s an old non-standard way of getting a button, with possible values:
event.which == 1
That’s not reliable, because the input can come from various sources.
So .at(-1) means the last character, and .at(-2) is the one before it, etc.… in str, starting from the given position pos, and returns the position where the match was found or -1… For instance, the first occurrence of "id" is at position 1.… So, we should actually check for -1, like this:
…And we’d like to use for..of loop on it, such as for(value of range), to get values from 1… iterators:
To make an object asynchronously iterable, it must have a method Symbol.asyncIterator (1)… Now values come with a delay of 1
Now let’s say we have an array [3, 5, 1]… And surely we can’t manually list items in the code Math.max(arr[0], arr[1]
this:
In the code above:
We load 1.… --
loadScript('1.js', function(error, script) {
if (error) {
handleError(error);
} else {
For instance, this function returns a resolved promise with the result of 1; let’s test it:… Here’s an example with a promise that resolves in 1 second:
As we can see, this phrase consists of exactly two children of <p>, with indexes 0 and 1:… E.g. selecting in the same <p> from offset 1… with 3 ranges, made in Firefox:
Other browsers support at maximum 1… imply that there may be many ranges, but again, in all browsers except Firefox, there’s at maximum 1.… selects nothing (empty range), or doesn’t exist.
rangeCount – count of ranges in the selection, maximum 1
They both call func with arguments 1,… Append glue and this[1].
Append glue and this[2].
…Do so until this.length items are glued.… So, technically it takes this and joins this[0], this[1] …etc together.
As of now, its length is 1.… If we use it instead, then both scripts output 1:
First, the hours:
If the first digit is 0 or 1, then the next digit can be any: [01]\d.
Only first 50 results are shown.