SOURCE

// 
function binaryAdd(num1, num2) {
    let a = parseInt(num1, 2);
    let b = parseInt(num2, 2);
    return parseInt(a+b).toString(2);
}
let res = binaryAdd('10100', '1011');
console.log('res', res);


function binaryAdd2(num1, num2) {
    let arr1 = num1.split('').reverse();
    let arr2 = num2.split('').reverse();
    let tmp =  arr1.length < arr2.length ? arr2 : arr1;
    for (let i = 0; i < tmp.length; i++) {
        arr1[i] = arr1[i] === undefined ? 0 : arr1[i];
        arr2[i] = arr2[i] === undefined ? 0 : arr2[i];
        if (parseInt(arr1[i]) + parseInt(arr2[i]) > 1) {
            if (tmp[i+1] === undefined) tmp[i+1] = 0;
            tmp[i+1] = parseInt(tmp[i+1]) + 1;
            tmp[i] %= 2;
        }
    }
    return tmp.reverse().join('')
}   

let tmp = binaryAdd2('10100', '1011');
console.log('tmp', tmp);
console 命令行工具 X clear

                    
>
console