what is the output of the following program?
xxxxxxxxxx
const myFunc = () => {
let a = 1;
setTimeout(() => console.log(a), 1000);
a = 2;
};
myFunc();
1] 1
2] 2
3] undefined
4] It will throw an error
And: 2
what is the output of following code
xxxxxxxxxx
let sum = 0;
function addSum(num) {
sum = sum + num;
console.log(sum);
}
addSum(3);
Options:
1] 3
2] 4
3] undefined
4] null
Ans: 1] 3
xxxxxxxxxx
const arr = [1, 2, 3, 4, 5];
const [a, b, c] = arr;
console.log(c);
//Options
a] [1,2,3,4]
b] [1,2]
c] [3,4,5]
d] [4]
Ans:
c] [3,4,5]
What JavaScript method is used to convert a string to a number?
xxxxxxxxxx
What JavaScript method is used to convert a string to a number?
a) toString()
b) toNumber()
c) parseInt()
d) slice()
what is the output of the following program
xxxxxxxxxx
var str = "1_2_3";
const result = str.split("_");
console.log(result);
1] [1,2,3]
2] 123
3] ['1','2','3']
4] none of them
Ans: 3
what is the output of the following program?
xxxxxxxxxx
function a(){
console.log("1")
}
a();
function a(){
console.log("2")
}
a();
1] 1,2
2] 2,1
3] 2,2
4] error
Answer: 3
what is the output of the following program
xxxxxxxxxx
for (let i = 1; i < 5; i++) {
if (i === 3) continue;
console.log(i);
}
1] 1 2 3
2] 1 2
3] 1 3 4
4] 1 2 4
Ans: 4]
xxxxxxxxxx
let string = "this is a string";
let num = "99";
let floatNum = 99;
console.log(string + num + floatNum);
//Options
1] this is a string9999.
2] this is a string198.
3] error
Ans: 1] this is a string9999.
xxxxxxxxxx
let count = 0;
const nums = [0, 1, 2, 3];
nums.forEach(num => {
if (num){
count += 1
}
})
console.log(count);
//Options
a] 1
b] 2
c] 3
d] 4
c] 3
xxxxxxxxxx
this = ["I", "am", "not", "a", "crook"]
that = ["I", "am", "not", "a", "crook"]
print("Test 1: {0}".format(this is that))
that = this
print("Test 2: {0}".format(this is that))