Skip to content

Commit d129186

Browse files
committed
Fix formatting issues
1 parent 24f0468 commit d129186

File tree

1 file changed

+118
-112
lines changed

1 file changed

+118
-112
lines changed

README.md

+118-112
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<div>
2020
<p align="center">
21-
<a href="https://www.frontendlead.com/coding-questions?utm_source=github&utm_medium=referral&ut%0Dm_campaign=sudheerj-js">
21+
<a href="https://www.frontendlead.com/coding-questions?utm_source=github&utm_medium=referral&ut%0Dm_campaign=sudheerj-js" rel="dofollow">
2222
<img src="./images/collab/frontendlead-banner.png" alt="FrontEndLead JavaScript Interview Questions" width="100%">
2323
</a>
2424
</p>
@@ -2428,18 +2428,18 @@
24282428

24292429
```javascript
24302430
<script>
2431-
var msg;
2432-
function greeting() {
2433-
alert('Good morning');
2434-
}
2435-
function start() {
2436-
msg =setTimeout(greeting, 3000);
2431+
var msg;
2432+
function greeting() {
2433+
alert('Good morning');
2434+
}
2435+
function start() {
2436+
msg =setTimeout(greeting, 3000);
24372437

2438-
}
2438+
}
24392439

2440-
function stop() {
2441-
clearTimeout(msg);
2442-
}
2440+
function stop() {
2441+
clearTimeout(msg);
2442+
}
24432443
</script>
24442444
```
24452445

@@ -2453,18 +2453,18 @@
24532453

24542454
```javascript
24552455
<script>
2456-
var msg;
2457-
function greeting() {
2458-
alert('Good morning');
2459-
}
2460-
function start() {
2461-
msg = setInterval(greeting, 3000);
2456+
var msg;
2457+
function greeting() {
2458+
alert('Good morning');
2459+
}
2460+
function start() {
2461+
msg = setInterval(greeting, 3000);
24622462

2463-
}
2463+
}
24642464

2465-
function stop() {
2466-
clearInterval(msg);
2467-
}
2465+
function stop() {
2466+
clearInterval(msg);
2467+
}
24682468
</script>
24692469
```
24702470

@@ -2494,15 +2494,15 @@
24942494
mainString.includes(subString);
24952495
```
24962496

2497-
1. **Using indexOf:** In an ES5 or older environment, you can use `String.prototype.indexOf` which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.
2497+
2. **Using indexOf:** In an ES5 or older environment, you can use `String.prototype.indexOf` which returns the index of a substring. If the index value is not equal to -1 then it means the substring exists in the main string.
24982498

24992499
```javascript
25002500
var mainString = "hello",
25012501
subString = "hell";
25022502
mainString.indexOf(subString) !== -1;
25032503
```
25042504

2505-
1. **Using RegEx:** The advanced solution is using Regular expression's test method(`RegExp.test`), which allows for testing for against regular expressions
2505+
3. **Using RegEx:** The advanced solution is using Regular expression's test method(`RegExp.test`), which allows for testing for against regular expressions
25062506
25072507
```javascript
25082508
var mainString = "hello",
@@ -2570,32 +2570,32 @@
25702570

25712571
1. **Using in operator:** You can use the in operator whether a key exists in an object or not
25722572

2573-
```javascript
2574-
"key" in obj;
2575-
```
2573+
```javascript
2574+
"key" in obj;
2575+
```
25762576

2577-
and If you want to check if a key doesn't exist, remember to use parenthesis,
2577+
and If you want to check if a key doesn't exist, remember to use parenthesis,
25782578
2579-
```javascript
2580-
!("key" in obj);
2581-
```
2579+
```javascript
2580+
!("key" in obj);
2581+
```
25822582
2583-
1. **Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instance (and not inherited properties)
2583+
2. **Using hasOwnProperty method:** You can use `hasOwnProperty` to particularly test for properties of the object instance (and not inherited properties)
25842584
2585-
```javascript
2586-
obj.hasOwnProperty("key"); // true
2587-
```
2585+
```javascript
2586+
obj.hasOwnProperty("key"); // true
2587+
```
25882588
2589-
1. **Using undefined comparison:** If you access a non-existing property from an object, the result is undefined. Let’s compare the properties against undefined to determine the existence of the property.
2589+
3. **Using undefined comparison:** If you access a non-existing property from an object, the result is undefined. Let’s compare the properties against undefined to determine the existence of the property.
25902590
2591-
```javascript
2592-
const user = {
2593-
name: "John",
2594-
};
2591+
```javascript
2592+
const user = {
2593+
name: "John",
2594+
};
25952595
2596-
console.log(user.name !== undefined); // true
2597-
console.log(user.nickName !== undefined); // false
2598-
```
2596+
console.log(user.name !== undefined); // true
2597+
console.log(user.nickName !== undefined); // false
2598+
```
25992599
26002600
**[⬆ Back to Top](#table-of-contents)**
26012601
@@ -2698,9 +2698,9 @@
26982698
26992699
#### Cons
27002700
2701-
1. Too verbose
2702-
2. Imperative
2703-
3. You might face off-by-one errors.
2701+
3. Too verbose
2702+
4. Imperative
2703+
5. You might face off-by-one errors.
27042704
27052705
**[⬆ Back to Top](#table-of-contents)**
27062706
@@ -2770,7 +2770,9 @@
27702770
27712771
135. ### How do you add a key value pair in javascript
27722772
2773-
There are two possible solutions to add new properties to an object. Let's take a simple object to explain these solutions.
2773+
There are two possible solutions to add new properties to an object.
2774+
2775+
Let's take a simple object to explain these solutions.
27742776

27752777
```javascript
27762778
var object = {
@@ -4490,10 +4492,10 @@
44904492

44914493
The above code processed in a call stack as below,
44924494

4493-
1. Add the `hungry()` function to the call stack list and execute the code.
4494-
2. Add the `eatFruits()` function to the call stack list and execute the code.
4495-
3. Delete the `eatFruits()` function from our call stack list.
4496-
4. Delete the `hungry()` function from the call stack list since there are no items anymore.
4495+
3. Add the `hungry()` function to the call stack list and execute the code.
4496+
4. Add the `eatFruits()` function to the call stack list and execute the code.
4497+
5. Delete the `eatFruits()` function from our call stack list.
4498+
6. Delete the `hungry()` function from the call stack list since there are no items anymore.
44974499

44984500
![Screenshot](images/call-stack.png)
44994501

@@ -4576,7 +4578,9 @@
45764578
45774579
243. ### What is the purpose of compareFunction while sorting arrays
45784580
4579-
The compareFunction is used to define the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value. Let's take an example to see the usage of compareFunction,
4581+
The compareFunction is used to define the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.
4582+
4583+
Let's take an example to see the usage of compareFunction,
45804584
45814585
```javascript
45824586
let numbers = [1, 2, 5, 3, 4];
@@ -5370,58 +5374,58 @@
53705374

53715375
1. **Using Object Literal Notation:** Let's wrap variables and functions inside an Object literal which acts as a namespace. After that you can access them using object notation
53725376

5373-
```javascript
5374-
var namespaceOne = {
5375-
function func1() {
5376-
console.log("This is a first definition");
5377+
```javascript
5378+
var namespaceOne = {
5379+
function func1() {
5380+
console.log("This is a first definition");
5381+
}
53775382
}
5378-
}
5379-
var namespaceTwo = {
5380-
function func1() {
5381-
console.log("This is a second definition");
5383+
var namespaceTwo = {
5384+
function func1() {
5385+
console.log("This is a second definition");
5386+
}
53825387
}
5383-
}
5384-
namespaceOne.func1(); // This is a first definition
5385-
namespaceTwo.func1(); // This is a second definition
5386-
```
5388+
namespaceOne.func1(); // This is a first definition
5389+
namespaceTwo.func1(); // This is a second definition
5390+
```
53875391

53885392
2. **Using IIFE (Immediately invoked function expression):** The outer pair of parentheses of IIFE creates a local scope for all the code inside of it and makes the anonymous function a function expression. Due to that, you can create the same function in two different function expressions to act as a namespace.
53895393

5390-
```javascript
5391-
(function () {
5392-
function fun1() {
5393-
console.log("This is a first definition");
5394-
}
5395-
fun1();
5396-
})();
5394+
```javascript
5395+
(function () {
5396+
function fun1() {
5397+
console.log("This is a first definition");
5398+
}
5399+
fun1();
5400+
})();
53975401

5398-
(function () {
5399-
function fun1() {
5400-
console.log("This is a second definition");
5401-
}
5402-
fun1();
5403-
})();
5404-
```
5402+
(function () {
5403+
function fun1() {
5404+
console.log("This is a second definition");
5405+
}
5406+
fun1();
5407+
})();
5408+
```
54055409

54065410
3. **Using a block and a let/const declaration:** In ECMAScript 6, you can simply use a block and a let declaration to restrict the scope of a variable to a block.
54075411

5408-
```javascript
5409-
{
5410-
let myFunction = function fun1() {
5411-
console.log("This is a first definition");
5412-
};
5413-
myFunction();
5414-
}
5415-
//myFunction(): ReferenceError: myFunction is not defined.
5412+
```javascript
5413+
{
5414+
let myFunction = function fun1() {
5415+
console.log("This is a first definition");
5416+
};
5417+
myFunction();
5418+
}
5419+
//myFunction(): ReferenceError: myFunction is not defined.
54165420
5417-
{
5418-
let myFunction = function fun1() {
5419-
console.log("This is a second definition");
5420-
};
5421-
myFunction();
5422-
}
5423-
//myFunction(): ReferenceError: myFunction is not defined.
5424-
```
5421+
{
5422+
let myFunction = function fun1() {
5423+
console.log("This is a second definition");
5424+
};
5425+
myFunction();
5426+
}
5427+
//myFunction(): ReferenceError: myFunction is not defined.
5428+
```
54255429

54265430
**[⬆ Back to Top](#table-of-contents)**
54275431

@@ -5946,20 +5950,20 @@
59465950
59475951
1. Import a module on-demand or conditionally. For example, if you want to load a polyfill on legacy browser
59485952
5949-
```javascript
5950-
if (isLegacyBrowser()) {
5951-
import(···)
5952-
.then(···);
5953-
}
5954-
```
5953+
```javascript
5954+
if (isLegacyBrowser()) {
5955+
import(···)
5956+
.then(···);
5957+
}
5958+
```
59555959
5956-
1. Compute the module specifier at runtime. For example, you can use it for internationalization.
5960+
2. Compute the module specifier at runtime. For example, you can use it for internationalization.
59575961
5958-
```javascript
5959-
import(`messages_${getLocale()}.js`).then(···);
5960-
```
5962+
```javascript
5963+
import(`messages_${getLocale()}.js`).then(···);
5964+
```
59615965
5962-
1. Import a module from within a regular script instead a module.
5966+
3. Import a module from within a regular script instead a module.
59635967
59645968
**[⬆ Back to Top](#table-of-contents)**
59655969
@@ -6017,7 +6021,7 @@
60176021
console.log(l10nSV.compare("ä", "z") === +1); // true
60186022
```
60196023
6020-
1. **Sorting:**
6024+
2. **Sorting:**
60216025
60226026
```javascript
60236027
var list = ["ä", "a", "z"]; // In German, "ä" sorts with "a" Whereas in Swedish, "ä" sorts after "z"
@@ -6236,11 +6240,11 @@
62366240
var n = 022;
62376241
```
62386242
6239-
1. Using `with` statement
6240-
2. When you use delete operator on a variable name
6241-
3. Using eval or arguments as variable or function argument name
6242-
4. When you use newly reserved keywords
6243-
5. When you declare a function in a block and access it from outside of the block
6243+
2. Using `with` statement
6244+
3. When you use delete operator on a variable name
6245+
4. Using eval or arguments as variable or function argument name
6246+
5. When you use newly reserved keywords
6247+
6. When you declare a function in a block and access it from outside of the block
62446248
62456249
```javascript
62466250
if (someCondition) {
@@ -7021,7 +7025,7 @@
70217025
70227026
In this API, browser is going to ask you for permission to use your microphone
70237027
7024-
1. **SpeechSynthesis (Text-to-Speech):** It provides the ability to recognize voice context from an audio input and respond. This is accessed by the `SpeechSynthesis` interface.
7028+
2. **SpeechSynthesis (Text-to-Speech):** It provides the ability to recognize voice context from an audio input and respond. This is accessed by the `SpeechSynthesis` interface.
70257029
For example, the below code is used to get voice/speech from text,
70267030
70277031
```javascript
@@ -8840,10 +8844,12 @@ The execution context is created when a function is called. The function's code
88408844
**[⬆ Back to Top](#table-of-contents)**
88418845
88428846
467. ### What is the difference between substring and substr methods?
8847+
Both substring() and substr() are string methods, which are used to find substring of a given string. But there are some notable differences with their usage,
8848+
88438849
88448850
**[⬆ Back to Top](#table-of-contents)**
88458851
8846-
468. ### How to find the number of parameters expected by a function?
8852+
1. ### How to find the number of parameters expected by a function?
88478853
The function's object has a **length** property which tells you how many formal parameters expected by a function. This is a static value defined by the function, not the number of arguments the function is called with(__arguments.length__). The basic usage of length propery is,
88488854
88498855
```javascript

0 commit comments

Comments
 (0)