Construção de Expressões

Descrição

Crie um algoritmo para as seguintes expressões considerando que a variável x possui o valor 8:

ExpressãoResultado
x+210
64
∛x2
3x²+12x-4284
x+3 > √xtrue

Explique o resultado de cada console.log:

// spread operator
const numbers = [1, 2, 3];
console.log(...numbers, 4, 5); //=> [1, 2, 3, 4, 5]
// prefix decrement
const number = 10;
console.log(--number); //=> 9
// delete operator
const numbers = [1, 2, 3];
delete numbers[1];
console.log(numbers); //=> [ 1, , 3 ]
// left shitf operator
console.log((127 & 0xff) << 24) | ((0 & 0xff) << 16) | ((0 & 0xff) << 8) | (1 & 0xff)); //=> 2130706433
// sign-propagating right shift operator
console.log((2130706433 >>> 24) & 0xff); //=> 127
console.log((2130706433 >>> 16) & 0xff); //=> 0
console.log((2130706433 >>> 8) & 0xff); //=> 0
console.log(2130706433 & 0xff); //=> 1
// left shitf operator
const octet1 = 127;
const octet2 = 0;
const octet3 = 0;
const octet4 = 1;
const ip =
  ((octet1 & 0xff) << 24) |
  ((octet2 & 0xff) << 16) |
  ((octet3 & 0xff) << 8) |
  (octet4 & 0xff);
console.log(ip); //=> 2130706433
// unary plus operator
const number = '15';
console.log(+number); //=>  15
// less than and greater than operator
const number = 1;
console.log(10 > number < 20); //=> true
// equality operator
console.log(1 == '1a'); //=> false
console.log(1 == '1'); //=> true
// identity/strict equality
console.log(1 === '1'); //=> false
// bitwise and operator
console.log((8 & 1) === 0); //=> true
console.log(!(8 & 1)); //=> true
console.log(!!(8 & 1)); //=> false
// logical or operator
let x;
const y = 10 || x;
console.log(y);

Códigos

Editar esta página