https://thedailyfrontend.com/how-to-create-html-elements-dynamically-and-bind-events-with-javascript/
Let's learn in detail 😌
How to Create HTML Elements Dynamically and Bind Events with JavaScript
Let's learn in detail 😌
How to Create HTML Elements Dynamically and Bind Events with JavaScript
The Daily Frontend
How to Create HTML Elements Dynamically and Bind Events with JavaScript - The Daily Frontend
Learn how to Create HTML Elements Dynamically and Bind Events with JavaScript step by step in this article.
DevScrolls
65. What's the output?
[1, 2, 3, 4].reduce((x, y) => console.log(x, y));
[1, 2, 3, 4].reduce((x, y) => console.log(x, y));
Answer: D
The first argument that the reduce method receives is the accumulator, x in this case. The second argument is the current value, y. With the reduce method, we execute a callback function on every element in the array, which could ultimately result in one single value.
In this example, we are not returning any values, we are simply logging the values of the accumulator and the current value.
The value of the accumulator is equal to the previously returned value of the callback function. If you don't pass the optional initialValue argument to the reduce method, the accumulator is equal to the first element on the first call.
On the first call, the accumulator (x) is 1, and the current value (y) is 2. We don't return from the callback function, we log the accumulator and current value: 1 and 2 get logged.
If you don't return a value from a function, it returns undefined. On the next call, the accumulator is undefined, and the current value is 3. undefined and 3 get logged.
On the fourth call, we again don't return from the callback function. The accumulator is again undefined, and the current value is 4. undefined and 4 get logged.
The first argument that the reduce method receives is the accumulator, x in this case. The second argument is the current value, y. With the reduce method, we execute a callback function on every element in the array, which could ultimately result in one single value.
In this example, we are not returning any values, we are simply logging the values of the accumulator and the current value.
The value of the accumulator is equal to the previously returned value of the callback function. If you don't pass the optional initialValue argument to the reduce method, the accumulator is equal to the first element on the first call.
On the first call, the accumulator (x) is 1, and the current value (y) is 2. We don't return from the callback function, we log the accumulator and current value: 1 and 2 get logged.
If you don't return a value from a function, it returns undefined. On the next call, the accumulator is undefined, and the current value is 3. undefined and 3 get logged.
On the fourth call, we again don't return from the callback function. The accumulator is again undefined, and the current value is 4. undefined and 4 get logged.
67. What's the output?
// index.js
console.log('running index.js');
import { sum } from './sum.js';
console.log(sum(1, 2));
// sum.js
console.log('running sum.js');
export const sum = (a, b) => a + b;
DevScrolls
67. What's the output? // index.js console.log('running index.js'); import { sum } from './sum.js'; console.log(sum(1, 2)); // sum.js console.log('running sum.js'); export const sum = (a, b) => a + b;
68. What's the output?
console.log(Number(2) === Number(2)); console.log(Boolean(false) === Boolean(false)); console.log(Symbol('foo') === Symbol('foo'));
console.log(Number(2) === Number(2)); console.log(Boolean(false) === Boolean(false)); console.log(Symbol('foo') === Symbol('foo'));
Anonymous Poll
35%
A: true, true, false
13%
B: false, true, false
4%
C: true, false, true
48%
D: true, true, true
❤1
69. What's the output?
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
Anonymous Poll
21%
A: "Lydia Hallie", "Lydia Hallie"
46%
B: " Lydia Hallie", " Lydia Hallie" ("[13x whitespace]Lydia Hallie", "[2x whitespace]Lydia Hallie")
8%
C: " Lydia Hallie", "Lydia Hallie" ("[1x whitespace]Lydia Hallie", "Lydia Hallie")
25%
D: "Lydia Hallie", "Lyd"
70. What's the output?
console.log('🥑' + '💻');
console.log('🥑' + '💻');
Anonymous Poll
65%
A: "🥑💻"
0%
B: 257548
14%
C: A string containing their code points
22%
D: Error
DevScrolls
69. What's the output?
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
const name = 'Lydia Hallie'; console.log(name.padStart(13)); console.log(name.padStart(2));
Answer: C
With the padStart method, we can add padding to the beginning of a string. The value passed to this method is the total length of the string together with the padding. The string "Lydia Hallie" has a length of 12. name.padStart(13) inserts 1 space at the start of the string, because 12 + 1 is 13.
If the argument passed to the padStart method is smaller than the length of the array, no padding will be added.
With the padStart method, we can add padding to the beginning of a string. The value passed to this method is the total length of the string together with the padding. The string "Lydia Hallie" has a length of 12. name.padStart(13) inserts 1 space at the start of the string, because 12 + 1 is 13.
If the argument passed to the padStart method is smaller than the length of the array, no padding will be added.
DevScrolls
70. What's the output?
console.log('🥑' + '💻');
console.log('🥑' + '💻');
Answer: A
With the + operator, you can concatenate strings. In this case, we are concatenating the string "🥑" with the string "💻", resulting in "🥑💻".
With the + operator, you can concatenate strings. In this case, we are concatenating the string "🥑" with the string "💻", resulting in "🥑💻".
72. What's the output?
console.log(String.raw`Hello\nworld`);
console.log(String.raw`Hello\nworld`);
Anonymous Poll
38%
A: Hello world!
16%
B: Hello world
41%
C: Hello\nworld
6%
D: Hello\n world