Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88f1101

Browse files
Added Questions-Answers-71-80
1 parent b5820f1 commit 88f1101

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

‎README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@
7575
| 68 | [What is an anonymous function](#68-what-is-an-anonymous-function) |
7676
| 69 | [What is a first order function](#69-what-is-a-first-order-function) |
7777
| 70 | [Different ways to access object properties in javascript](#70-different-ways-to-access-object-properties-in-javascript) |
78+
| 71 | [Difference between slice() and splice()](#71-difference-between-slice-and-splice) |
79+
| 72 | [What are the escape characters in JavaScript](#72-what-are-the-escape-characters-in-javascript) |
80+
| 73 | [Different ways to redirect a page in javascript](#73-different-ways-to-redirect-a-page-in-javascript) |
81+
| 74 | [What is the difference between innerHTML and innerText](#74-what-is-the-difference-between-innerhtml-and-innertext) |
82+
| 75 | [How can you get current time using js](#75-how-can-you-get-current-time-using-js) |
83+
| 76 | [What is currying](#76-what-is-currying) |
84+
| 77 | [Difference between shallow copy and deep copy](#77-difference-between-shallow-copy-and-deep-copy) |
85+
| 78 | [What is a service worker](#78-what-is-a-service-worker) |
86+
| 79 | [What is JSON](#79-what-is-json) |
87+
| 80 | [How can you get all the keys of any object](#80-how-can-you-get-all-the-keys-of-any-object) |
7888

7989
### 1. What is JavaScript
8090
* JavaScript is a scripting language used to create dynamic and interactive websites. It is supported by all major web browsers.
@@ -1056,6 +1066,131 @@ console.log(name, designation) // output ========> "Surbhi","SE"
10561066
10571067
**[:top: Scroll to Top](#javascript-interview-questions)**
10581068
1069+
### 71. Difference between slice() and splice()
1070+
**slice()** - This method creates a new array by copying a specified section of an existing array and returns that new array. This operation does not modify the original array in any way.
1071+
```js
1072+
const arr=[1,2,3,4,5];
1073+
const result = arr.slice(2)
1074+
console.log(arr); // output ========> [1, 2, 3, 4, 5]
1075+
console.log(result); // output ========> [3, 4, 5]
1076+
```
1077+
1078+
**splice()** - This method is used to add or remove elements from an array. It modifies the original array and returns an array containing the removed elements (if any).
1079+
```js
1080+
const arr=[1,2,3,4,5];
1081+
const result = arr.splice(2)
1082+
console.log(arr); // output ========> [1, 2]
1083+
console.log(result); // output ========> [3, 4, 5]
1084+
```
1085+
1086+
**[:top: Scroll to Top](#javascript-interview-questions)**
1087+
1088+
### 72. What are the escape characters in JavaScript
1089+
When working with special characters such as ampersands (&), apostrophes ('), double quotes (" "), and single quotes (' '). JavaScript requires the use of escape characters, which are often represented by the backslash (\). These escape characters instruct JavaScript to interpret the special characters correctly.
1090+
Below are some common escape characters in JavaScript:
1091+
- \n - Represents a newline character.
1092+
- \t - Represents a tab character.
1093+
- \' - Represents a single quote character.
1094+
- \" - Represents a double quote character.
1095+
- \\ - Represents a backslash character.
1096+
- \r - Represents a carriage return character.
1097+
1098+
**[:top: Scroll to Top](#javascript-interview-questions)**
1099+
1100+
### 73. Different ways to redirect a page in javascript
1101+
**location.href** - It is used to navigate to a new page and add it to the browser's history.
1102+
```js
1103+
window.location.href = "https://www.example.com";
1104+
```
1105+
**location.replace** - It is used to replace the current page with a new page without adding it to the history.
1106+
```js
1107+
window.location.replace("https://www.example.com");
1108+
```
1109+
**[:top: Scroll to Top](#javascript-interview-questions)**
1110+
1111+
### 74. What is the difference between innerHTML and innerText
1112+
innerHTML retrieves or modifies the HTML content of an element, including its tags, while innerText only retrieves or modifies the text content of an element, excluding any HTML tags.
1113+
```js
1114+
//HTML code
1115+
<div id="example">Hello <strong>world</strong>!</div>
1116+
1117+
//Javascript code
1118+
let result = document.getElementById("example").innerHTML;
1119+
console.log(result); // output ========> "Hello <strong>world</strong>!"
1120+
```
1121+
```js
1122+
//HTML code
1123+
<div id="example">Hello <strong>world</strong>!</div>
1124+
1125+
//Javascript code
1126+
let result = document.getElementById("example").innerText;
1127+
console.log(result); // output ========> "Hello world!"
1128+
```
1129+
**[:top: Scroll to Top](#javascript-interview-questions)**
1130+
1131+
### 75. How can you get current time using js
1132+
To get the current time using JavaScript, you can use the built-in Date object.
1133+
```js
1134+
let currentTime = new Date();
1135+
let hours = currentTime.getHours();
1136+
let minutes = currentTime.getMinutes();
1137+
let seconds = currentTime.getSeconds();
1138+
console.log(`Current time is ${hours}:${minutes}:${seconds}`); // output ========> "Current time is 16:7:22"
1139+
```
1140+
1141+
**[:top: Scroll to Top](#javascript-interview-questions)**
1142+
1143+
### 76. What is currying
1144+
Currying is the process of breaking down a function that takes multiple arguments into a series of functions that take a single argument.
1145+
```js
1146+
const add = (a, b) => {
1147+
return a + b;
1148+
}
1149+
const curryingAdd = (a) => (b) => a + b;
1150+
console.log(add(5, 4)); // output ========> 9
1151+
console.log(curryingAdd(5)(4)); // output ========> 9
1152+
```
1153+
**[:top: Scroll to Top](#javascript-interview-questions)**
1154+
1155+
### 77. Difference between shallow copy and deep copy
1156+
**shallow copy** - It creates a new object that points to the same memory location as the original object. Therefore, any changes made to the original object will also be reflected in the shallow copy. It can be done using the spread operator or object.assign() method.
1157+
1158+
**deep copy** - It creates a completely new object with its own memory space. This means that any changes made to the original object will not be reflected in the deep copy. It can be done using the JSON.parse() and JSON.stringify() methods.
1159+
1160+
**[:top: Scroll to Top](#javascript-interview-questions)**
1161+
1162+
### 78. What is a service worker
1163+
A service worker is a kind of web worker that operates in the background of a web page, decoupled from the primary browser thread, and capable of executing diverse tasks. It is essentially a JavaScript file that is associated with a web page and executes independently, without depending on the user interface.
1164+
1165+
**[:top: Scroll to Top](#javascript-interview-questions)**
1166+
1167+
### 79. What is JSON
1168+
JSON (JavaScript Object Notation) is a lightweight data interchange format that is easy for humans to read and write, and easy for machines to parse and generate.
1169+
```js
1170+
{
1171+
"users":[
1172+
{"name":"Test1", "age":"20"},
1173+
{"name":"Test2", "age":"30"},
1174+
{"name":"Test3", "age":"40"}
1175+
]
1176+
}
1177+
```
1178+
1179+
**[:top: Scroll to Top](#javascript-interview-questions)**
1180+
1181+
### 80. How can you get all the keys of any object
1182+
The Object.keys() method returns an array containing all the keys of the object
1183+
```js
1184+
const obj1 = {
1185+
name: 'Surbhi',
1186+
city: 'Indore'
1187+
};
1188+
const keys = Object.keys(obj1);
1189+
console.log(keys); // output ========> ["name", "city"]
1190+
```
1191+
1192+
**[:top: Scroll to Top](#javascript-interview-questions)**
1193+
10591194
## Output Based Questions
10601195
10611196
**1. What will be the output**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /