JavaScript

A common interview question

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// const list1 = [1, 2, 3, 4, 5]
// const list2 = list1
// list1.push(6, 7, 8)

// console.log(list2)

// ==============================
// second half of the question

const list1 = [1, 2, 3, 4, 5]
const list2 = list1.slice()
list1.push(6, 7, 8)

console.log('list1: ', list1)
console.log('list2: ', list2)
Native Browser JavaScript