+ 14
Explain the output of this code !!!!!
var num1 = [1,2] ; var num2 = [3,4] ; var set = num1 + num2 ; console.log(set.length); Output : 6 Why output is 6 ?? How it works ???
28 Réponses
+ 9
This happen because "+" sign works for numbers and strings. And here "+" automatically convert array to string: "1,2"+"3,4" = "1,23,4". So "1,23,4" as string has length 6.
+ 8
What is the output of the following code?
let nums = [3, 4, 5];
let all = [1, 2, ...nums, 6];
console.log(all[3]);
answer
4
+ 5
hangout..? i dont use it....
+ 4
I am also done.
+ 4
Parisa Baastani Console.log output any statement in java script. Document.write display it in html document but console.log displays it directly in console.
+ 3
Vladi Petrov Thank you so much !!!!
+ 3
im done.....
+ 3
Vladi Petrov Thank you so much. I would like to ask a question. Would you like to join our programming group ???
+ 3
Ok
+ 3
i dont know about cinsole.log, anybody here to explain about it?
+ 3
Hi,
'var' datatype behaves as what type of data is initialized that's why initialization is necessary while declaring 'var' variable.
'+' sign is considered as concatenate operator when used with string values.
Since right side is string then 'var' will behave like a string.
Length function returns the length of a string that's why answer is 6.
Thanks,
Jai Patel
+ 3
What is the output of this code?
function letItBe() {
let v = 2;
if (true) {
let v = 4;
console.log(v);
}
console.log(v);
}
letItBe();
Ans: 4 2
+ 2
S. Kaouche Nope It isn't because of .length method
+ 1
[3] means, the fourth ---> 4
0
ya that what i was thinking...
0
if you are counting "commas(,)", then also length will be 5. Why are you taking 23 separately? they are single as number twenty three(according to what output you showed)
0
ya.. shit now i got that.. i just forgot nd got confused.. sorry Vladi
0
Isn't it because of the .length method which add 0 position to each array ?
So it becomes 0,1,2 (num1)+ 0,3,4 (num2)= 6
The 0 position index is included in the .length method , isn't it ?
0
you can add two arrays in JS using the concat method. var v = a.concat(arr); console.log(v)
0
What is the output of the following code?
let nums = [3, 4, 5];
let all = [1, 2, ...nums, 6];
console.log(all[3]);
answer
4