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 e56d744

Browse files
Question-Answer 42-43
1 parent 329364c commit e56d744

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

‎README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Top JavaScript interview questions
4747
| 39 | [How do we add comments in javascript](#39-how-do-we-add-comments-in-javascript) |
4848
| 40 | [What is the use of typeof operator](#40-what-is-the-use-of-typeof-operator) |
4949
| 41 | [Is JavaScript case-sensitive](#41-is-javascript-case-sensitive) |
50+
| 42 | [Difference between push() and unshift()](#42-difference-between-push-and-unshift) |
51+
| 43 | [Difference between pop() and shift()](#43-difference-between-pop-and-shift) |
5052

5153
### 1. What is JavaScript
5254
* JavaScript is a scripting language used to create dynamic and interactive websites. It is supported by all major web browsers.
@@ -625,6 +627,43 @@ Yes, JavaScript is a case-sensitive language. For e.g., the variables firstName
625627
let firstName = "Surbhi";
626628
console.log(firstname); // output ========> Uncaught ReferenceError: firstname is not defined
627629
```
630+
631+
### 42. Difference between push() and unshift()
632+
Both are used to add elements to an array, but they add elements in different ways.
633+
634+
**push()** - It adds one or more elements to the end of an array and returns the new length of the array.
635+
```js
636+
let arr = [1,2,3,4];
637+
let newArr = arr.push(5,6,7);
638+
console.log(newArr); // output ========> 7
639+
console.log(arr); // output ========> [1, 2, 3, 4, 5, 6, 7]
640+
```
641+
**unshift()** - It adds one or more elements to the beginning of an array and returns the new length of the array.
642+
```js
643+
let arr = [1,2,3,4];
644+
let newArr = arr.unshift(5,6,7);
645+
console.log(newArr); // output ========> 7
646+
console.log(arr); // output ========> [5, 6, 7, 1, 2, 3, 4]
647+
```
648+
649+
### 43. Difference between pop() and shift()
650+
Both are used to remove elements from an array, but they remove elements in different ways.
651+
652+
**pop()** - It removes the last element of an array and returns the removed element.
653+
```js
654+
let arr = [1,2,3,4];
655+
let newArr = arr.pop();
656+
console.log(newArr); // output ========> 4
657+
console.log(arr); // output ========> [1,2,3]
658+
```
659+
660+
**shift()** - It removes the first element of an array and returns the removed element.
661+
```js
662+
let arr = [1,2,3,4];
663+
let newArr = arr.shift();
664+
console.log(newArr); // output ========> 1
665+
console.log(arr); // output ========> [2,3,4]
666+
```
628667
******************************In progress
629668
630669

0 commit comments

Comments
(0)

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