|
1 | 1 | # JavaScript Interview Questions & Answers |
2 | 2 |
|
3 | | -> Click :star:if you like the project and follow [@SudheerJonna](https://twitter.com/SudheerJonna) for more updates. Coding questions available [here](#coding-exercise). Check [DataStructures and Algorithms](https://github.com/sudheerj/datastructures-algorithms) for DSA related questions and [ECMAScript](https://github.com/sudheerj/ECMAScript-features) for all ES features.). |
| 3 | +> Click :star:if you like the project and follow [@SudheerJonna](https://twitter.com/SudheerJonna) for more updates. Coding questions available [here](#coding-exercise). Check [DataStructures and Algorithms](https://github.com/sudheerj/datastructures-algorithms) for DSA related questions and [ECMAScript](https://github.com/sudheerj/ECMAScript-features) for all ES features.) |
4 | 4 |
|
5 | 5 | --- |
6 | 6 |
|
|
145 | 145 | | 122 | [How do you validate an email in javascript](#how-do-you-validate-an-email-in-javascript) | |
146 | 146 | | 123 | [How do you get the current url with javascript](#how-do-you-get-the-current-url-with-javascript) | |
147 | 147 | | 124 | [What are the various url properties of location object](#what-are-the-various-url-properties-of-location-object) | |
148 | | -| 125 | [How do get query string values in javascript](#how-do-get-query-string-values-in-javascript) | |
| 148 | +| 125 | [How do you get query string values in javascript](#how-do-you-get-query-string-values-in-javascript) | |
149 | 149 | | 126 | [How do you check if a key exists in an object](#how-do-you-check-if-a-key-exists-in-an-object) | |
150 | 150 | | 127 | [How do you loop through or enumerate javascript object](#how-do-you-loop-through-or-enumerate-javascript-object) | |
151 | 151 | | 128 | [How do you test for an empty object](#how-do-you-test-for-an-empty-object) | |
@@ -1384,7 +1384,7 @@ Because of hoisting, functions can be used before they are declared. |
1384 | 1384 |
|
1385 | 1385 | 27. ### What are classes in ES6 |
1386 | 1386 |
|
1387 | | - In ES6, Javascript classes are primarily syntactic sugar over JavaScript’s existing prototype-based inheritance. |
| 1387 | + In ES6, JavaScript classes are primarily syntactic sugar over JavaScript’s existing prototype-based inheritance. |
1388 | 1388 | For example, the prototype based inheritance written in function expression as below, |
1389 | 1389 |
|
1390 | 1390 | ```javascript |
@@ -2805,7 +2805,7 @@ Because of hoisting, functions can be used before they are declared. |
2805 | 2805 |
|
2806 | 2806 | **[⬆ Back to Top](#table-of-contents)** |
2807 | 2807 |
|
2808 | | -125. ### How do get query string values in javascript |
| 2808 | +125. ### How do you get query string values in javascript |
2809 | 2809 |
|
2810 | 2810 | You can use URLSearchParams to get query string values in javascript. Let's see an example to get the client code value from URL query string, |
2811 | 2811 |
|
@@ -3435,7 +3435,7 @@ Because of hoisting, functions can be used before they are declared. |
3435 | 3435 |
|
3436 | 3436 | 163. ### What would be the result of 1+2+'3' |
3437 | 3437 |
|
3438 | | - The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`. Other operationrs like `3 * '3'` do yield correct results because the string is coerced into a number. |
| 3438 | + The output is going to be `33`. Since `1` and `2` are numeric values, the result of the first two digits is going to be a numeric value `3`. The next digit is a string type value because of that the addition of numeric value `3` and string type value `3` is just going to be a concatenation value `33`. Other operations like `3 * '3'` do yield correct results because the string is coerced into a number. |
3439 | 3439 |
|
3440 | 3440 | **[⬆ Back to Top](#table-of-contents)** |
3441 | 3441 |
|
@@ -3521,7 +3521,7 @@ Because of hoisting, functions can be used before they are declared. |
3521 | 3521 |
|
3522 | 3522 | 169. ### How do you get the image width and height using JS |
3523 | 3523 |
|
3524 | | - You can programmatically get the image and check the dimensions(width and height) using Javascript. |
| 3524 | + You can programmatically get the image and check the dimensions(width and height) using JavaScript. |
3525 | 3525 |
|
3526 | 3526 | ```javascript |
3527 | 3527 | var img = new Image(); |
@@ -3580,7 +3580,7 @@ Because of hoisting, functions can be used before they are declared. |
3580 | 3580 |
|
3581 | 3581 | 173. ### What are the properties used to get size of window |
3582 | 3582 |
|
3583 | | - You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use them combination of these properties to calculate the size of a window or document, |
| 3583 | + You can use innerWidth, innerHeight, clientWidth, clientHeight properties of windows, document element and document body objects to find the size of a window. Let's use a combination of these properties to calculate the size of a window or document, |
3584 | 3584 |
|
3585 | 3585 | ```javascript |
3586 | 3586 | var width = |
@@ -5313,7 +5313,7 @@ Because of hoisting, functions can be used before they are declared. |
5313 | 5313 | 273. ### How do you perform form validation using javascript |
5314 | 5314 |
|
5315 | 5315 | JavaScript can be used to perform HTML form validation. For example, if the form field is empty, the function needs to notify, and return false, to prevent the form being submitted. |
5316 | | - Lets' perform user login in an html form, |
| 5316 | + Let's perform user login in an html form, |
5317 | 5317 |
|
5318 | 5318 | ```html |
5319 | 5319 | <form name="myForm" onsubmit="return validateForm()" method="post"> |
@@ -5603,7 +5603,7 @@ Because of hoisting, functions can be used before they are declared. |
5603 | 5603 |
|
5604 | 5604 | 290. ### What is the difference between java and javascript |
5605 | 5605 |
|
5606 | | - Both are totally unrelated programming languages and no relation between them. Java is statically typed, compiled, runs on its own VM. Whereas Javascript is dynamically typed, interpreted, and runs in a browser and nodejs environments. Let's see the major differences in a tabular format, |
| 5606 | + Both are totally unrelated programming languages and no relation between them. Java is statically typed, compiled, runs on its own VM. Whereas JavaScript is dynamically typed, interpreted, and runs in a browser and nodejs environments. Let's see the major differences in a tabular format, |
5607 | 5607 | | Feature | Java | JavaScript | |
5608 | 5608 | |---- | ---- | ----- |
5609 | 5609 | | Typed | It's a strongly typed language | It's a dynamic typed language | |
@@ -6924,7 +6924,7 @@ Because of hoisting, functions can be used before they are declared. |
6924 | 6924 |
|
6925 | 6925 | ```javascript |
6926 | 6926 | const obj = { x: 1 }; |
6927 | | - // Grabs obj.x as as { otherName } |
| 6927 | + // Grabs obj.x as { otherName } |
6928 | 6928 | const { x: otherName } = obj; |
6929 | 6929 | ``` |
6930 | 6930 |
|
@@ -9058,7 +9058,7 @@ The polyfills for array methods such as map, filter and reduce methods can be cr |
9058 | 9058 |
|
9059 | 9059 | Both map and forEach functions are used to iterate over an arrays but there are some differences in their functionality. |
9060 | 9060 |
|
9061 | | - 1. **Returning values:** The `map` method returns a new array with transformed elements whereas `forEach` method returns `undefined` eventhough both of them are doing the same job. |
| 9061 | + 1. **Returning values:** The `map` method returns a new array with transformed elements whereas `forEach` method returns `undefined` even though both of them are doing the same job. |
9062 | 9062 |
|
9063 | 9063 | ```javascript |
9064 | 9064 | const arr = [1, 2, 3, 4, 5]; |
@@ -12450,7 +12450,7 @@ console.log(arr.sort()); |
12450 | 12450 |
|
12451 | 12451 | ##### Answer: 3 |
12452 | 12452 |
|
12453 | | -Javascript has a native method sort that allows sorting an array of elements in-place. It will treat each element as a string and sort it alphabetically. But if you try to sort an array of strings which has non-ASCII characters, you will receive a strange result. This is because characters with an accent have higher character codes. |
| 12453 | +JavaScript has a native method sort that allows sorting an array of elements in-place. It will treat each element as a string and sort it alphabetically. But if you try to sort an array of strings which has non-ASCII characters, you will receive a strange result. This is because characters with an accent have higher character codes. |
12454 | 12454 |
|
12455 | 12455 | In this case, the sort order of an array is ['Wann', 'Woche', 'wäre', 'wöchentlich']. |
12456 | 12456 |
|
|
0 commit comments