@jgCarroll/

objectsAndStrings

JavaScript

A common interview question.

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var string1 = 'Tampa';
var string2 = string1;
string1 = 'Venice';
 
console.log(string2); // logs Tampa. Strings are passed by value, so the reassignment of string1 doesn't affect string2
 
 
////////////////////////////////
 
 
var person1 = {
  name: 'Alex',
  age: 30
};
 
var person2 = person1;
 
person2.name = 'Kyle';
 
console.log(person1); // logs { name: 'Kyle', age: 30 }
Native Browser JavaScript