What is the output of the following TypeScript code?let arr = [1, 2, 3, 4];for (let i = 0; i < arr.length; i++) { if (i === 2) continue; console.log(arr[i]);}*1 point1 2 3 41 3 41 2 41 2 4 3
Question
What is the output of the following TypeScript code?let arr = [1, 2, 3, 4];for (let i = 0; i < arr.length; i++) { if (i === 2) continue; console.log(arr[i]);}*1 point1 2 3 41 3 41 2 41 2 4 3
Solution
The output of the given TypeScript code will be:
1 2 4
This is because the 'continue' statement skips the current iteration of the loop when 'i' equals 2, so the value at index 2 (which is 3) is not logged to the console.
Similar Questions
What will be the output of the following TypeScript code?let array = [10, 20, 30];for (let value of array) { console.log(value);}*1 point0 1 210 20 30value[10, 20, 30]
What will be the output of the following TypeScript code?let i = 0;do { i++;} while (i < 3);console.log(i);*1 point0123
6What will the code below output to the console and why?const obj = {a: 1,b: 2};const arr = [];console.log(arr[0] = { ...obj });Review Later1,2{…obj}{a: 1, b: 2}Does not compile
Consider this code snippet: 'const [a, b] = [1,2,3,4] '. What is the value of b?1 pointundefined12[1,2,3,4]
What's the output of the following code?public static void main(String[] args) { int[] vals = {4, 3, 2, 1}; for (int v : vals) { System.out.println(indexOf(vals, v)); }}public static int indexOf(int[] all, int element) { for (int i = 0; i < all.length; i++) { if (all[i] == element) return i; } return -1;}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.