Skip to content

Instantly share code, notes, and snippets.

@darleykrefta
Created March 20, 2021 13:19
Show Gist options
  • Save darleykrefta/bee536cfd459c2847cc84f7350a66d4f to your computer and use it in GitHub Desktop.
Save darleykrefta/bee536cfd459c2847cc84f7350a66d4f to your computer and use it in GitHub Desktop.
const jedis = ['Yoda', 'Luke Skywalker', 'Qui-Gon Jinn', 'Rey']

// define jedisSorted with jedis sorted reference
const jedisSorted = jedis.sort()

// the original variable is updated too, because it is the original reference
console.log(jedis)
// ['Luke Skywalker', 'Qui-Gon Jinn', 'Rey', 'Yoda']

// variable jedisSorted was updated by the reference
console.log(jedisSorted)
// ['Luke Skywalker', 'Qui-Gon Jinn', 'Rey', 'Yoda']

// define jedisReversed with jedis reversed reference
const jedisReversed = jedis.reverse()

// the original variable is updated too, because it is the original reference
console.log(jedis)
// ['Yoda', 'Rey', 'Qui-Gon Jinn', 'Luke Skywalker']

// variable jedisSorted was updated by the reference
console.log(jedisReversed)
// ['Yoda', 'Rey', 'Qui-Gon Jinn', 'Luke Skywalker']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment