Binary representation in JS

by alex_o

JavaScript

let num = 4;
 console.log(num.toString(2));  // 100
 
 num = 255;
 console.log(num.toString(2)); // 11111111
 console.log(num.toString()); // 255
 
 let num2 = console.log(parseInt('011', 2));  // 3 
 let num3 = console.log(parseInt( num, 2)); // will be NaN, because first parameter of parseInt should be string