SOURCE

var target = '10101';
var result = 0;

var len = target.length;
for(var i = 0; i < len; i++){
    result += Number(target[i]) * Math.pow(2,len - 1 - i);
}
console.log(result);
console 命令行工具 X clear

                    
>
console