JS Mini Challenges Week 1

JS Mini Challenges Week 1

·

2 min read

Guess the outputs without executing the code

var foo = function(){
    var args = Array.prototype.slice.call(arguments);
    console.log(args[1])
}
foo(1,2,4) //?
const obj1 = {
    a: 5,
    b: {
        c: 6
    }
}

const obj2 = Object.assign({}, obj1)
const obj3 = { ...obj1 }
obj1.b.c = 8
console.log(obj2)  //?
console.log(obj3)  //?
console.log(Object.assign({}, obj1, obj2, obj3)) //?
console.log(null == undefined) //?
console.log(null === undefined) //?
var power = "100"
function getPowerNumber() {
    var power = "10"
    function f() {
        return power
    }
    return f
}
console.log(getPowerNumber()()) //?
var obj = { hasOwnProperty: 1, foo: 2 }
console.log(obj.hasOwnProperty('foo')) //?
function person(id, name) {
    var id = id
    var name = name
}

function student(id, name) {
    person.call(this, id, name)
}

console.log(new student(50, "Sravanth").id);//?
console.log(Boolean("false") === Boolean(false)); //?
let foo = (a = 3, b = 5) => {
    console.log(a + b);
}

foo(7, 4) //?
function foo() {
    console.log(a); //?
    var a = 4;
    console.log(a); //?
}

foo()
function foo() {
    console.log(a); //?
    let a = 4;
    console.log(a); //?
}

foo()
const first = 6 * "JS";
const second = 6 * "JS";
console.log(first !== second )//?

// Answer: 
//In the lines number 9 and 10, a number is multiplied by a string which will return 
//NaN. Since NaN(not a number) is not equal to anything, not even itself; //true will be 
//logged to the console.

Did you find this article valuable?

Support Sravanth by becoming a sponsor. Any amount is appreciated!