From 3fab75d44c18cd7e804667c85e974129e11c529c Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Mon, 25 Sep 2023 17:22:21 +0600 Subject: [PATCH] wip: add more questions --- .../javascript/content/defer-vs-async.md | 25 +++++++++++++++++++ .../javascript/content/increment-operator.md | 21 ++++++++++++++++ .../question-groups/javascript/javascript.md | 10 ++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/data/question-groups/javascript/content/defer-vs-async.md create mode 100644 src/data/question-groups/javascript/content/increment-operator.md diff --git a/src/data/question-groups/javascript/content/defer-vs-async.md b/src/data/question-groups/javascript/content/defer-vs-async.md new file mode 100644 index 000000000..74c032c6e --- /dev/null +++ b/src/data/question-groups/javascript/content/defer-vs-async.md @@ -0,0 +1,25 @@ +The main difference between `defer` and `async` is the order of execution. + +## Defer attribute + +A ` + +``` + +In the example above, `script1.js` will be executed before `script2.js`. The browser will download both scripts in parallel, but `script1.js` will be executed after the HTML page has been parsed and `script2.js` will be executed after `script1.js` has been executed. + +## Async attribute + +On the other hand, A ` + +``` + +In the example above, the browser will download both scripts in parallel, and execute them as soon as they are downloaded. The order of execution is not guaranteed. + +To know more you can check [this diagram](https://roadmap.sh/guides/avoid-render-blocking-javascript-with-async-defer) from us that explains the difference between `defer` and `async` in a visual way. diff --git a/src/data/question-groups/javascript/content/increment-operator.md b/src/data/question-groups/javascript/content/increment-operator.md new file mode 100644 index 000000000..b27669b44 --- /dev/null +++ b/src/data/question-groups/javascript/content/increment-operator.md @@ -0,0 +1,21 @@ +As the name says, the increment operator increases the value of a variable by **1**. There are two types of increment operators: `pre-increment` and `post-increment`. + +## Pre-increment + +The pre-increment operator increases the value of a variable by 1 and then returns the value. For example: + +```js +let x = 1; +console.log(++x); // 2 +console.log(x); // 2 +``` + +## Post-increment + +The post-increment operator returns the value of a variable and then increases the value by 1. For example: + +```js +let x = 1; +console.log(x++); // 1 +console.log(x); // 2 +``` diff --git a/src/data/question-groups/javascript/javascript.md b/src/data/question-groups/javascript/javascript.md index 34c25c087..4de946ea5 100644 --- a/src/data/question-groups/javascript/javascript.md +++ b/src/data/question-groups/javascript/javascript.md @@ -236,4 +236,14 @@ questions: topics: - 'Core' - 'Intermediate' + - question: Difference between `defer` and `async` attributes in JavaScript? + answer: defer-vs-async.md + topics: + - 'Core' + - 'Beginner' + - question: What is Increment operator in JavaScript? + answer: increment-operator.md + topics: + - 'Core' + - 'Beginner' ---