JSE1 – Final Test Answers (JavaScript Essentials 1)

JSE1 − Final Test Answers (JavaScript Essentials 1)

1. Examine the following code:

let a = (n) => {
    return n > 2 ? n * a(n - 1) : 2
}
a(6);

What will appear on the console as a result?

  • 6
  • 720
  • 120
  • 4

2. Placing a debugger; statement in the program code will:

  • cause the console to display the completion status of the statement preceding the debugger.
  • put the interpreter into report mode, which will cause the console to print out all sequentially executed commands.
  • pause the program with the ability to continue, as long as the execution environment supports “debugging functionality”.
  • stop the program without the ability to continue, as long as the execution environment supports “debugging functionality”.

3. We can replace the declaration let x = 3e-3; with:

  • let x = 0.003;
  • let x = 0.333;
  • let x = 0.0003;
  • let x = 3000;

4. Using the string interpolation technique, we can create the string "I do not like travelling by plane" and store it in the msg variable using the command:

  • let means = "plane";
    let msg = ' I do not like travelling by ${means}';
  • let means = "plane";
    let msg = ' I do not like travelling by {means}';
  • let means = "plane";
    let msg = " I do not like travelling by ${ means }";
  • let means = "plane";
    let msg = " I do not like travelling by \{ means \}";

5. Examine the following code:

let x = [10, 20, 30, 40];
let y = [50, 60];
x.reverse().push(y);
console.log(x.length);

What will appear on the console as a result?

  • 6
  • 5
  • 2
  • 4

6. Review the following code:

let msg1 = 'hello';
let msg2 = msg1.slice(-1);
console.log(msg2 ? msg2 : msg2 + msg1);

What will appear on the console as a result?

  • hello
  • ohello
  • o
  • h

7. In the daysOfWeek variable, we place an array with the names of the days of the week. To reverse the order of the array elements, we should call:

  • daysOfWeek.order(-1);
  • daysOfWeek.invert();
  • daysOfWeek = reverse(daysOfWeek);
  • daysOfWeek.reverse();

8. We have declared an array of animals: let animals = ["canary", "dog", "cat"];. Then we call the method animals.push("hamster");. As a result, the animals array will look like this:

  • ["canary", "dog", "cat"]
  • ["hamster", "canary", "dog", "cat"]
  • ["canary", "dog", "cat", "hamster"]
  • ["hamster"]

9. Analyze the following code:

const a = "hello";
try {
    console.log(a.toUpperCase());
} catch (error) {
    console.log(a)
} finally {
    console.log(a);
}

What will happen as a result of its execution?

  • The following words will appear in the console: hello, hello.
  • The following words will appear in the console: HELLO, hello.
  • The words HELLO, hello, hello will appear in the console on subsequent lines.
  • The word HELLO will appear in the console.

10. Analyze the following code:

let x = false || true;
let y = "true" && "false";
let z = false && true;
console.log('${x}  ${y}  ${z}');

What will appear in the console as a result of its execution?

  • false false true
  • false false false
  • false true true
  • true false false

11. Examine the following code:

let x = mult(2)(10);
console.log(x); // -> 20

What should the mult function declaration look like if the execution of this code results in a value of 20 in the console?

  • let mult = function (a, b) {
        return b ? mult(b) : mult(a);
    }
  • let mult = function (a, b) {
        return a * b;
    }
  • let mult = function (a) {
        return function (b) {
            return a * b;
        }
    }
  • There is an error in the code and it is not possible to declare such a function correctly.

12. Analyze the following code:

let a = true && 20;
let b = 0 || 20
let c = 0 && 20;
console.log('${a}  ${b}  ${c}');

What will appear in the console as a result of its execution?

  • true 20 0
  • 1 1 0
  • true true false
  • 20 20 0

13. Analyze the code snippet:

let winter = ["December", "January", "February"];
let index = winter.indexOf("February");

The index variable will have the value:

  • "February"
  • 2
  • 3
  • 1

14. We declare a movie object, with two fields: title and year:

let movie = {
    title: "aga",
    year: 2018
};

To change the value of the title field to "Ága" we need to perform:

  • movie.title = "Ága";
  • movie{title} = "Ága";
  • title->movie = "Ága";
  • movie[title] = "Ága";

15. Analyze the following code:

let colors = ['red', 'green', 'blue'];
for (let c of colors) console.log(c);

What will appear on the console as a result?

  • red green blue
  • 0 1 2
  • ['red', 'green', 'blue']
  • 3

16. Examine the following code:

let a = 20 + "10";
let b = 20 + +"10";
let c = 20 + -"10" + "10";
let d = "10" - "10" + "100";
let e = "A" - "B" + 0xA;
console.log('${a}, ${b}, ${c}, ${d}, ${e}');

What will appear on the console as a result?

  • 30, 31, 39, 100, NaN
  • 30, 30, 20, 100, 2
  • 2010, 2010, 20-1010, 0100, NaN
  • 2010, 30, 1010, 0100, NaN

17. The JavaScript code includes the console.log("http://somethingNew.org"); command. Its execution will:

  • send a log with information about the currently executed script to the indicated address http://somethingNew.org.
  • display on the console information about the progress of the http://somethingNew.org page loading.
  • display the following message on the console: "http://somethingNew.org".
  • cause the page http://test.org to be loaded into the browser.

18. Examine the following code:

x = [40, 10, 30, 20, 50];
x.sort(cmp);

How should the function cmp be declared if, after the code execution, the elements of the array x are sorted in ascending order?

  • let cmp = (a, b) => b - a;
  • let cmp = (a, b) => b < a;
  • let cmp = (a, b) => b > a;
  • let cmp = (a, b) => a - b;

19. We define a function using a function expression:

let sum = function (a, b) {
    return (a + b);
}

What could the definition of the corresponding arrow function look like?

  • let sum = (a, b) => { a + b; };
  • let sum = (a, b)-- > a + b;
  • let sum = function (a, b)
    =>
    {
        return (a + b);
    }
  • let sum = (a, b) => a + b;

20. Analyze the code snippet:

let counter = 0;
let userName = "John";

After declaring the counter variable, we want to add a short comment with information about what the variable is used for. To do this, we modify the line with the declaration to the form:

  • let counter = 0; // user visit counter
  • let counter = 0; /* user visit counter
  • let counter = 0; ;;user visit counter
  • // let counter = 0; user visit counter

21. The temp array contains air temperature data measured over a period of time. We want to display the minimal temperature, and to do so we write the following code:

temp.forEach(e => min = min > e ? e : min);
console.log(min);

In the code, we use the variable sum, which should be previously declared as follows:

  • let min = temp[0];
  • It’s not necessary, as it will be declared automatically on first use.
  • let min = 0;
  • let min;

22. Which of the following loop instructions checks the loop continuation condition only after the iteration has been completed?

  • while
  • do ... while
  • for ... in
  • for

23. Analyze the following code:

function execute(todo, a, b) {
    return todo(a, b);
}

console.log(execute(power, 3, 2));

Before declaring the function, we should add one more line of code. Which one, if the execution of the completed code will result in the console displaying the value 9?

  • let power = () => a ** b;
  • let power = (x, y) => x ** y;
  • let power = (x,y) => x * y;
  • let power = 9;

24. Analyze the following code:

let route = {distance: 131, elevation: 1.4};
for (let k in route) console.log(k);

What will appear on the console as a result?

  • "distance"
  • 131 1.4
  • "distance" "elevation"
  • 2

25. Analyze the following code:

let test = prompt("Run", "code");

What value will the test variable have if, after running the code, we immediately press the OK
button on the newly created dialog?

  • "code"
  • "OK"
  • "Run"
  • true

26. Analyze the following code:

let id = "100";
{
    let id = 200;
    id = id + 1;
    console.log(id);
}

What will appear to the console as a result?

  • 101
  • 1001
  • 201
  • 200

27. Entering about:blank in the address bar of your browser will:

  • generate a page with information about the browser's status.
  • open a tab with information about your browser.
  • generate and load a minimal blank HTML page into the current tab.
  • clear all inputs on the current page.

28. Analyze the following code:

for (let a = 5; a > 2; a--) {
    console.log(a);
};

Which statement can replace the for from the example?

  • let counter = 0;
    while (counter++ < 10) console.log(counter++);
  • let counter = 0;
    while (counter < 10) console.log(counter++);
  • let counter = 1;
    while (counter++ < 10) console.log(counter++);
  • let counter = 0;
    while (counter < 9) console.log(counter++);

29. Select a set of data types, containing only complex types:

  • Array, Object
  • Array, Object, String
  • Boolean, Number, Bigint
  • Object, String

30. In the following code fragment, where we use setInterval, one line is missing – the place is marked in gray:

let counter = 2;
let interval = setInterval(() => {
    console.log(counter);

}, 1000);

What should the missing line look like if the execution of this code results in the console displaying the values 2, 1, and 0 in sequence?

  • if (counter-- <= 0) clearInterval(interval);
  • while (counter-- >= 0) clearInterval(interval);
  • clearInterval(interval);
  • if (counter-- >= 0) clearInterval(interval);

Leave a Reply

Your email address will not be published. Required fields are marked *