Skip to content

Commit bd6fb9a

Browse files
authored
I have added more content to advanced questions section (#190)
* added content to interview questions basic and advanced section * reolved conflicts && removed yarn.lock and package-lock.json * I have added some more questions in basci level of Interview Questions * added some questions in basic and advanced level of interview questions * added some intermediate level questions to interview questions section * removed duplicate content from the basic interview questions * added more content to advanced questions section
1 parent 59826de commit bd6fb9a

File tree

2 files changed

+253
-0
lines changed

2 files changed

+253
-0
lines changed

en/interview-questions/advance-level.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,212 @@ JavaScript modules, along with the ES6 import/export syntax, are crucial for mod
189189
**Answer:**
190190
Template literals in ES6 enhance string manipulation by allowing developers to create strings with embedded expressions and multiline content in a more readable and flexible way. They support variable interpolation, multiline strings, expression evaluation, function calls, and even advanced use cases like tagged templates. This feature improves code readability and maintainability when working with complex strings that involve dynamic content or expressions.
191191

192+
### 7.4. Can I redeclare let and const variables ?
193+
194+
**Answer:**
195+
196+
No, you cannot redeclare let and const variables. If you do, it throws below error.
197+
198+
```js
199+
Uncaught SyntaxError: Identifier 'someVariable' has already been declared
200+
```
201+
202+
Explanation: The variable declaration with var keyword refers to a function scope and the variable is treated as if it were declared at the top of the enclosing scope due to hoisting feature. So all the multiple declarations contributing to the same hoisted variable without any error. Let's take an example of re-declaring variables in the same scope for both var and let/const variables.
203+
204+
```js
205+
var name = "John";
206+
function myFunc() {
207+
var name = "Nick";
208+
var name = "Abraham"; // Re-assigned in the same function block
209+
alert(name); // Abraham
210+
}
211+
myFunc();
212+
alert(name); // John
213+
```
214+
215+
The block-scoped multi-declaration throws syntax error,
216+
217+
```js
218+
let name = "John";
219+
function myFunc() {
220+
let name = "Nick";
221+
let name = "Abraham"; // Uncaught SyntaxError: Identifier 'name' has already been declared
222+
alert(name);
223+
}
224+
225+
myFunc();
226+
alert(name);
227+
```
228+
229+
### 7.5. Is const variable makes the value immutable ?
230+
231+
**Answer:**
232+
233+
No, the const variable doesn't make the value immutable. But it disallows subsequent assignments(i.e, You can declare with assignment but can't assign another value later)
234+
235+
```js
236+
const userList = [];
237+
userList.push("John"); // Can mutate even though it can't re-assign
238+
console.log(userList); // ['John']
239+
```
240+
241+
### 7.6. What are default parameters ?
242+
243+
**Answer:**
244+
245+
In ES5, we need to depend on logical OR operators to handle default values of function parameters. Whereas in ES6, Default function parameters feature allows parameters to be initialized with default values if no value or undefined is passed. Let's compare the behavior with an examples,
246+
247+
```js
248+
//ES5
249+
var calculateArea = function (height, width) {
250+
height = height || 50;
251+
width = width || 60;
252+
253+
return width * height;
254+
};
255+
console.log(calculateArea()); //300
256+
```
257+
258+
The default parameters makes the initialization more simpler,
259+
260+
```js
261+
//ES6
262+
var calculateArea = function (height = 50, width = 60) {
263+
return width * height;
264+
};
265+
266+
console.log(calculateArea()); //300
267+
```
268+
269+
### 7.7. What are template literals ?
270+
271+
**Answer:**
272+
273+
Template literals or template strings are string literals allowing embedded expressions. These are enclosed by the back-tick (`) character instead of double or single quotes. In ES6, this feature enables using dynamic expressions as below,
274+
275+
```js
276+
var greeting = `Welcome to JS World, Mr. ${firstName} ${lastName}.`;
277+
```
278+
279+
In ES5, you need break string like below,
280+
281+
```js
282+
var greeting = 'Welcome to JS World, Mr. ' + firstName + ' ' + lastName.`
283+
```
284+
285+
Note: You can use multi-line strings and string interpolation features with template literals.
286+
287+
### 7.8. How do you write multi-line strings in template literals ?
288+
289+
**Answer:**
290+
291+
In ES5, you would have to use newline escape characters('\n') and concatenation symbols(+) in order to get multi-line strings.
292+
293+
```js
294+
console.log("This is string sentence 1\n" + "This is string sentence 2");
295+
```
296+
297+
Whereas in ES6, You don't need to mention any newline sequence character,
298+
299+
```js
300+
console.log(`This is string sentence 'This is string sentence 2`);
301+
```
302+
303+
### 7.9. What are nesting templates ?
304+
305+
**Answer:**
306+
307+
The nesting template is a feature supported within template literals syntax to allow inner backticks inside a placeholder ${ } within the template. For example, the below nesting template is used to display the icons based on user permissions whereas outer template checks for platform type,
308+
309+
```js
310+
const iconStyles = `icon ${
311+
isMobilePlatform()
312+
? ""
313+
: `icon-${user.isAuthorized ? "submit" : "disabled"}`
314+
}`;
315+
```
316+
You can write the above use case without nesting template features as well. However, the nesting template feature is more compact and readable.
317+
318+
```js
319+
//Without nesting templates
320+
const iconStyles = `icon ${
321+
isMobilePlatform()
322+
? ""
323+
: user.isAuthorized
324+
? "icon-submit"
325+
: "icon-disabled"
326+
}`;
327+
```
328+
329+
### 7.10. What are tagged templates ?
330+
331+
**Answer:**
332+
333+
Tagged templates are the advanced form of templates in which tags allow you to parse template literals with a function. The tag function accepts the first parameter as an array of strings and remaining parameters as expressions. This function can also return manipulated strings based on parameters. Let's see the usage of this tagged template behavior of an IT professional skill set in an organization,
334+
335+
```js
336+
var user1 = "John";
337+
var skill1 = "JavaScript";
338+
var experience1 = 15;
339+
340+
var user2 = "Kane";
341+
var skill2 = "JavaScript";
342+
var experience2 = 5;
343+
344+
function myInfoTag(strings, userExp, experienceExp, skillExp) {
345+
var str0 = strings[0]; // "Mr/Ms. "
346+
var str1 = strings[1]; // " is a/an "
347+
var str2 = strings[2]; // "in"
348+
349+
var expertiseStr;
350+
if (experienceExp > 10) {
351+
expertiseStr = "expert developer";
352+
} else if (skillExp > 5 && skillExp <= 10) {
353+
expertiseStr = "senior developer";
354+
} else {
355+
expertiseStr = "junior developer";
356+
}
357+
358+
return `${str0}${userExp}${str1}${expertiseStr}${str2}${skillExp}`;
359+
}
360+
361+
var output1 = myInfoTag`Mr/Ms. ${user1} is a/an ${experience1} in ${skill1}`;
362+
var output2 = myInfoTag`Mr/Ms. ${user2} is a/an ${experience2} in ${skill2}`;
363+
364+
console.log(output1); // Mr/Ms. John is a/an expert developer in JavaScript
365+
console.log(output2); // Mr/Ms. Kane is a/an junior developer in JavaScript
366+
```
367+
368+
### 7.11. What are raw strings ?
369+
370+
**Answer:**
371+
372+
ES6 provides a raw strings feature using the String.raw() method which is used to get the raw string form of template strings. This feature allows you to access the raw strings as they were entered, without processing escape sequences. For example, the usage would be as below,
373+
374+
```js
375+
var calculationString = String.raw`The sum of numbers is \n${
376+
1 + 2 + 3 + 4
377+
}!`;
378+
console.log(calculationString); // The sum of numbers is \n10!
379+
```
380+
381+
If you don't use raw strings, the newline character sequence will be processed by displaying the output in multiple lines
382+
383+
```js
384+
var calculationString = `The sum of numbers is \n${1 + 2 + 3 + 4}!`;
385+
console.log(calculationString);
386+
// The sum of numbers is
387+
// 10!
388+
```
389+
390+
Also, the raw property is available on the first argument to the tag function
391+
392+
```js
393+
function tag(strings) {
394+
console.log(strings.raw[0]);
395+
}
396+
```
397+
192398
## 8. Functional Programming
193399

194400
### 8.1. How does functional programming differ from imperative programming in JavaScript?

en/interview-questions/basic-level.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,53 @@ JavaScript is an interpreted language, not a compiled language. An interpreter i
839839

840840
Yes, JavaScript is a case sensitive language. The language keywords, variables, function & object names, and any other identifiers must always be typed with a consistent capitalization of letters.
841841

842+
## 6.Miscellaneous
843+
844+
### 6.1. What is a strict mode in JavaScript ?
845+
846+
**Answer:**
847+
848+
Strict Mode is a new feature in ECMAScript 5 that allows you to place a program, or a function, in a "strict" operating context. This way it prevents certain actions from being taken and throws more exceptions. The literal expression "use strict"; instructs the browser to use the javascript code in the Strict mode.
849+
850+
### 6.2. What is null value in JavaScript ?
851+
852+
**Answer:**
853+
854+
The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values. The type of null value is object. You can empty the variable by setting the value to null.
855+
856+
```js
857+
var user = null;
858+
console.log(typeof user); //object
859+
```
860+
861+
### 6.3. What is eval in JavaScript ?
862+
863+
**Answer:**
864+
865+
The eval() function evaluates JavaScript code represented as a string. The string can be a JavaScript expression, variable, statement, or sequence of statements.
866+
867+
```js
868+
console.log(eval("1 + 2")); // 3
869+
```
870+
871+
### 6.4. Is JavaScript a compiled or interpreted language ?
872+
873+
**Answer:**
874+
875+
JavaScript is an interpreted language, not a compiled language. An interpreter in the browser reads over the JavaScript code, interprets each line, and runs it. Nowadays modern browsers use a technology known as Just-In-Time (JIT) compilation, which compiles JavaScript to executable bytecode just as it is about to run.
876+
877+
### 6.5. difference between exec () and test () methods
878+
879+
**Answer**
880+
881+
-> exec():
882+
1) It is an expression method in JavaScript that is used to search a string with a specific pattern.
883+
2) Once it has been found, the pattern will be returned directly, otherwise, it returns an “empty” result.
884+
885+
-> test ()
886+
1) It is an expression method in JavaScript that is also used to search a string with a specific pattern or text.
887+
2) Once it has been found, the pattern will return the Boolean value 'true', else it returns ‘false’.
888+
842889

843890
## 7.JSON
844891

0 commit comments

Comments
 (0)