+ 4
JS Challenges questions
Hi, while doing JS challenges I came across these two questions which solution I still cant figure out. 1. Question var nums1 = [1,2]; var nums2 = [3,4]; var set = nums1 + nums2; console.log(set.length); // Output: 6 2. Question var x = 1, y = 1, z = 0; do{ z = x + y; } while(++x <= 1 && y++ >= 1); z += x + y; document.write(z); // Output: 5 Can someone please help me and explain it? Thanks a lot in advance.
5 odpowiedzi
+ 12
Arrays have their own implementation of toString method that returns a comma separated list of elements:
let arr = [1, 2, 3, 4];
console.log(String(arr) === '1,2,3,4'); //true
+ 4
1.adding two arrays using '+' will return string
2.understand how do while loops work
understand how that && works
first iteration x = 1,y = 1
so,z = 2
then > ++x <= 1
x will increment to 2 first then compare
the statement become false, and what comes after the statement (y++>=1) wont get executed
now z = 2,x = 2,y = 1
z = 5
just understand the basic how things work..then u can solve the question✌
+ 3
1. Type conversation to string.
You have: 1,23,4.length => 6
+ 1
Thanks alot everyone!