shift operator javascript code example

Example 1: javascript shift

let array = ["A", "B", "C"];

//Removes the first element of the array
array.shift();

//===========================
console.log(array);
//output =>
//["B", "C"]

Example 2: right shift operator js

(A >> B) == Math.floor(A / (2 ** B)) == Math.floor(A / Math.pow(2, B))

Example 3: javascript bitwise flags

var myEnum = {
  left: 1,
  right: 2,
  top: 4,
  bottom: 8
}

var myConfig = myEnum.left | myEnum.right;

if (myConfig & myEnum.right) {
  // right flag is set
}