wip: add more questions

chore/javascript
Arik Chakma 1 year ago
parent e9651c6afe
commit 6713b059e1
  1. 19
      src/data/question-groups/javascript/content/explicit-binding.md
  2. 17
      src/data/question-groups/javascript/content/set-interval.md
  3. 16
      src/data/question-groups/javascript/content/set-timeout.md
  4. 20
      src/data/question-groups/javascript/javascript.md

@ -0,0 +1,19 @@
Explicit binding is a way to explicitly state what the `this` keyword is going to be bound to using `call`, `apply` or `bind` methods of a function.
```js
const roadmap = {
name: 'JavaScript',
};
function printName() {
console.log(this.name);
}
printName.call(roadmap); // JavaScript
printName.apply(roadmap); // JavaScript
const printRoadmapName = printName.bind(roadmap);
printRoadmapName(); // JavaScript
```
In the above example, the `this` keyword inside the `printName()` function is explicitly bound to the `roadmap` object using `call`, `apply` or `bind` methods.

@ -0,0 +1,17 @@
You can run some codes on interval using `setInterval` function in JavaScript. It accepts a function and a time interval in milliseconds. It returns a unique id which you can use to clear the interval using `clearInterval` function.
```js
const intervalId = setInterval(() => {
console.log('Hello World');
}, 1000);
// Output:
// Hello World
// Hello World
```
In the above code, the `setInterval` function runs the callback function every 1000 milliseconds (1 second) and prints `Hello World` to the console. It returns a unique id which you can use to clear the interval using `clearInterval` function.
```js
clearInterval(intervalId);
```

@ -0,0 +1,16 @@
To run a piece of code after a certain time, you can use `setTimeout` function in JavaScript. It accepts a function and a time interval in milliseconds. It returns a unique id which you can use to clear the timeout using `clearTimeout` function.
```js
const timeoutId = setTimeout(() => {
console.log('Hello World');
}, 1000);
// Output:
// Hello World
```
In the above code, the `setTimeout` function runs the callback function after 1000 milliseconds (1 second) and prints `Hello World` to the console. It returns a unique id which you can use to clear the timeout using `clearTimeout` function.
```js
clearTimeout(timeoutId);
```

@ -211,4 +211,24 @@ questions:
topics: topics:
- 'Core' - 'Core'
- 'Advanced' - 'Advanced'
- question: What is Type Casting?
answer: Type conversion (or typecasting) means transfer of data from one data type to another. Implicit conversion happens when the compiler (for compiled languages) or runtime (for script languages like `JavaScript`) automatically converts data types.
topics:
- 'Core'
- 'Intermediate'
- question: What are Explicit binding in JavaScript?
answer: explicit-binding.md
topics:
- 'Core'
- 'Advanced'
- question: How to run a piece of code after a specific time interval?
answer: set-interval.md
topics:
- 'Core'
- 'Beginner'
- question: How to run a piece of code only once after a specific time?
answer: set-timeout.md
topics:
- 'Core'
- 'Beginner'
--- ---

Loading…
Cancel
Save