Q:

Javascript, If statement with dictionary value equal to array?

I am fairly new to javascript and for some reason my program doesn't work. I have a dictionary using the key set to a string and the value euqal to an array full of booleans, I.E:
dict = {x: [true, false]}
but for some reason when I run the dictionary through an if statement, like 
if (dict[x] == [true, false]) {do something }
it fails to trigger. I was wondering what I am doing wrong

A:

Arrays and Objects are not primitive types but reference types in JavaScript.

This means that when comparing arrays and objects, you are actually comparing the references to these entities, and not their content. When you assign this array to another variable, you are simply making that variable reference the same content, but you are not copying this content:

const a = [1, 2, 3];
const b = [1, 2, 3];

console.log(a !== b);

const c = a;

console.log(a === c);

c[0] = 10;

console.log(a);

In your case, if you want to make sure your array contains true followed by false, you can use Array.every() or more simply just use array indexing to check the elements since the array is short:

const a = [true, false];

if (a.every((x, i) => x === [true, false][i])) {
  console.log('same content');
}

if (a[0] === true && a[1] === false) {
  console.log('same content');
}

