100% found this document useful (1 vote)
2K views43 pages

Java Script Essentials 1 Answers

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (1 vote)
2K views43 pages

Java Script Essentials 1 Answers

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 43

lOMoARcPSD|23010253

Java Script Essentials 1 answers

JavaScript Essentials 1 (AMA Computer University)

Escanea para abrir en Studocu

Studocu no está patrocinado ni avalado por ningún colegio o universidad.


Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)
lOMoARcPSD|23010253

JSE1: Module 1 Test Answers (JavaScript


Essentials 1)
November 8, 2022 JavaScript Essentials 1 Leave a comment

JavaScript Essentials 1 – JSE1: Module 1 Test Answers


1. Using JavaScript, we want to display the word “test” in the console. What
statement do we use to do this?
 console (log, “test”);

 log(“test”);

 console(“test”);

 console.log(“test”);

2. The basic toolkit needed to effectively develop JavaScript code consists of two
elements:
 interpreter, debugger.

 code editor, debugger.

 interpreter, package manager.

 code editor, interpreter.

3. The TypeScript language is:


 a variant of JavaScript that is compiled rather than interpreted.

 the original name for JavaScript, which has been changed over time.

 a new language based on JavaScript which, among other things, introduces static
typing.

 an alternative name for JavaScript.

4. The <html> tag indicates the start of the actual HTML document. What tag should
appear at the end of the document?
 <html/>

 </html>

 <lmth>

 <html>

5. Where will we definitely not be able to execute JavaScript code?


 In a web browser.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 In a server environment using node.js.

 On a mobile device.

 Directly in the processor.

6. What HTML tag is used to indicate that we are embedding JavaScript code?
 <source>

 <script>

 <js>

 <execute>

7. What is not the task of the interpreter?


 Creating a runtime environment for the program.

 Transforming the individual commands of the source code into the target form.

 Transforming all program code into target code before execution.

 Verifying the correctness of the program source code (syntax).

8. In the browser, we type into the address bar a string starting with file:///. This
means that:
 we want the browser to create an empty page for us with the name we give as a
continuation of the string.

 the rest of the string is the path to the file on our local computer that we want to
open in the browser.

 we want to save the page as a local file.

 we do not want to open the page, but only download a file from the remote address and
save it on the local machine.

9. In a browser, we want to open a local file by typing the path to it in the address bar.
The path must be preceded by:
 http://

 local:///

 https://

 file:///

10. A client-side JavaScript program:


 should be embedded inside an HTML document.

 may be embedded inside an HTML document or run standalone in the browser.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 runs directly in a web browser and can contain an HTML document inside it.

 requires server support to run.

11. HTML is:


 a language for describing the structure of a web page.

 a scripting language to support mathematical calculations.

 one of the data-compression formats.

 a network protocol.

12. The JavaScript code includes the console.log(“http://test.org”); command. Its


execution will:
 send a log with information about the currently executed script to the indicated address
http://test.org.

 display the following message on the console: “http://test.org”.

 cause the page http://test.org to be loaded into the browser.

 display on the console information about the progress of http://test.org page loading.

13. What tag do we use in HTML to denote the main part of the document inside
which we define the page elements?
 <head>

 <main>

 <body>

 <content>

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


 generate and load a minimal blank HTML page into the current tab.

 open a tab with information about your browser.

 reset the browser to its default settings.

 generate a page with information about the browser’s status and send it to the
developer.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

JSE1: Module 2 Test Answers (JavaScript


Essentials 1)
November 9, 2022 JavaScript Essentials 1 Leave a comment

JavaScript Essentials 1 – JSE1: Module 2 Test Answers


1. Analyze the code snippet:
let name;

let age;

let height; // 2

{ // 2

let weight; // 1 // 2

console.log(name); // 1 // 2

} // 2

console.log(name); // 2

We have access to the weight variable:


 in the part marked 1.

 throughout the program.

 in the part marked 2.

 nowhere, as we have no access at all (the variable has not been initialized).
2. Performing the operation: let x = "Alice" + 10; will result in:
 the value 15 of Number type to be stored in the variable x.

 the program execution to abort due to an error.

 the value NaN of Number type to be stored in the variable x.

 the value “Alice10” of String type to be stored in the variable x.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

3. Analyze the code snippet:


let summer = ["June", "July", "August"];

let index = summer.indexOf("June");

The index variable will have the value:


 1

 True

 0

 “June”

4. The msg variable contains a String type value. Information about the number of
characters of this string can be obtained using:
 msg.length

 msg.charsAt()

 msg.chars

 msg.length()

5. Performing the operation: let x = 100 / 0; will result in:


 an undefined value being stored in the variable x.

 the value NaN being stored in the variable x.

 an Infinity value being stored in the variable x.

 the value 0 being stored in the variable x.

6. Analyze the following code:


let counter = 100;

let counter = 200;

counter = 300;

As a result of its execution:


 the counter variable will have the value 100.

 the counter variable will have the value 200.

 the program will be aborted due to an error (redeclaration of a variable).

 the counter variable will have the value 300.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

7. Review the following code (note the variable name):


let age = 32;

age = age + 1;

console.log(Age);

As a result of its execution, the following should appear in the console:


 error message: “Uncaught ReferenceError: Age is not defined”.

 33

 32

 undefined

8. Complex (or composite) data types:


 is an alternative name for primitive types.

 may consist of multiple elements, each of which is of a primitive type.

 are not used in JavaScript.

 may consist of multiple elements, each of which may be of a primitive or


composite type.

9. We have declared an array of animals let animals = [“dog”, “cat”, “hamster”];.


Then we call the method animals.push(“canary”);. As a result, the animals array will
look like this:
 [“canary”, “dog”, “cat”, “hamster”]

 [“dog”, “cat”, “hamster”]

 [“dog”, “cat”, “hamster”, “canary”]

 [“canary”]

10. We need to come up with a name for a variable where we will store the age of a
user. All of the following variable names are formally correct, but one of them is the
most readable, indicate which one:
 ua

 userAge

 user

 age

11. Analyze the following code:

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

let height = 180;

let heigh = 200;

height = height + 10;

console.log(height);

As a result of its execution:


 the program will be terminated due to an error (re-declaration of the height variable).

 a value of 210 will be displayed in the console.

 a value of 200 will be displayed in the console.

 a value of 180 will be displayed in the console.

12. We have declared an array of selected month names let summer = [ “June”,
“July”, “August”];. We want to change the value “July” stored in the array to the
number 7:
 summer[1] = 7;

 We cannot do this (an array can only contain elements of the same type).

 summer[0] = 7;

 summer.July = 7;

13. In order to check the number of elements of the array stored in the names
variable, we call:
 length of names;

 name.length

 names.count

 names.length();

14. Analyze the following code:


let x = 10 / 100;

console.log(typeof (x));

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

As a result of its execution:


 an error will appear because JavaScript does not allow operations on fractional
numbers.

 it will display “Number” in the console.

 it will display “Fraction” in the console.

 it will display 0.1 in the console.

15. Analyze the code snippet:


let counter = 0;

let userName = "John";

After declaring a counter variable, we want to put 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

16. Performing the operation: let x = 20n + 10; will result in:
 cause the program to abort due to an error.

 result in a value of 30 being stored in the variable x.

 result in a value of 30n being stored in the variable x.

 result in the string “20n10” being stored in the variable x.

17. We declare an object called dog, with two fields: age and name:
let dog = {

age: 5.

name: "Axel"

};

To change the value of the age field to 6, we need to perform:


 age of dog = 6;

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 dog{age} = 6;

 dog.age = 6;

 dog[age] = 6;

18. If a variable stores the value false, then the variable:


 will no longer be used in the program.

 is of the Logical type.

 is of the Boolean type.

 is of the Math type.

19. We perform the operation: let x = “abcdefg”.slice(2, 4). As a result, the value:
 “cdef” will be written to the variable x.

 “ab” will be written to the variable x.

 “cd” will be written to the variable x.

 “cdefg” will be written to the variable x.

20. 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.reverse();

 invert(daysOfWeek);

 reverse daysOfWeek;

 daysOfWeek.invert();

21. We have declared an array let animals = [“dog”, “cat”, “hamster”];. We want to
temporarily comment out the element “cat”, and to do this, we can modify the
declaration as follows:
 let animals = [“dog”, #”cat”,# “hamster”];

 let animals = [“dog”, //”cat”,// “hamster”];

 let animals = [“dog”, “hamster”];

 let animals = [“dog”, /*”cat”,*/ “hamster”];

22. What does shadowing mean?


 Declaring a local variable with the same name as the previously declared global
variable.

 Changing the value of a variable.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 Declaring a global variable with the same name as a previously declared global variable.

 Deleting and rewriting a selected piece of program code.

23. Analyze the code snippet. Identify which variables are local and which are global:
let name;

let age;

let profession;

let height;

let weight;

 name : global
 profession : local
 age : global
 height : local
 weight : local
24. We want to declare a distance constant and initialize it with the value 120. What
should such a declaration look like?
 let constant distance = 120;

 const distance; distance = 120;

 let distance; const distance = 120;

 const distance = 120;

25. By default, JavaScript allows us to write to an undeclared variable (it declares it


implicitly for us). If we want the interpreter to treat such a situation as an error, we
have to:
 place the “use strict”; directive at the beginning of the script.

 place the “prevent undeclared variables”; directive at the beginning of the script.

 perform all writes to variables in a block of code delimited by braces.

 place the “use strict”; directive before each write we want to protect.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

26. Point out the correct declaration of the height variable:


 let height;

 height is variable;

 height;

 variable height;

27. We want to convert the string “1024” to type Number and store the result in
variable n. Point out the correct statement:
 let n = StringToNumber(“1024”);

 let n = String(“1024”);

 let n = Number(“1024”);

 let n = “1024” + 0;

28. We have declared an array of animals let animals = [“dog”, “cat”, “hamster”];.
Then we call the method animals.pop();. As a result, the animals array will look like
this:
 [“dog”, “cat”, “hamster”]

 [“cat”, “hamster”]

 [“dog”, “cat”]

 [“hamster”]

29. We can replace the declaration let x = 0x21; with:


 let x = 33;

 let x = 21;

 let x = 17;

 let x = “0x21”

JSE1: Module 3 Test Answers (JavaScript


Essentials 1)
November 9, 2022 JavaScript Essentials 1 Leave a comment

JavaScript Essentials 1 – JSE1: Module 3 Test Answers


1. The result of the operation !(true && false || true) will be:
 false

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 1

 true

 null

2. The result of the comparison “abcd” > “Abcd” will be:


 1

 false

 true

 “abcd”

3. Analyze the code snippet:


let nr = "1";

let x = (nr === 1);

let y = (nr == 1);

let z = (nr = 1);

After its execution, the variables x, y, and z will have the values:
 x: true, y: false, z: 1

 x: 1, y: 1, z: 1

 x: false, y: true, z: 1

 x: null, y: null, z: 1

4. The result of the operation 3 * 4 > 20 – 15 will be:


 true

 -14

 NaN

 false

5. Analyze the code snippet:


let n = 10;

let m = ++n;

Its execution will result in the following values in the variables n and m:

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 n: 10, m: 11

 n: 11, m: 10

 n: 11, m: 11

 n: 10, m: 10

6. The confirm method allows you to create a dialog box. What value does this
method return when the user closes the window?
 The string entered by the user.

 Always true.

 It depends on the option selected by the user.

 Always false.

7. Which operator do we use if we want to check if two variables store the same
values of exactly the same type?
 =

 !==

 ==

 ===

8. The result of the operation false || “false” will be:


 true

 0

 false

 “false”

9. The number 2 is stored in the variable n (let n = 2;). The command n = n*n*n is then
called. This last command can be replaced by:
 n ***= n;

 n *= 3;

 n **= 3;

 n **= n;

10. Analyze the following code:


let test = prompt("Hello", "World");

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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

 “World”

 true

 “Hello”

11. The result of the operation 20 || 5 will be:


 20

 5

 true

 25

12. Analyze the code snippet:


let n = 2 * 3 ** 3 - 1;

The result stored in the variable n is:


 53

 215

 18

 36

13. The methods window.alert, window.confirm, and window.prompt are methods of


the window object. Which of the following is not true?
 The window object represents the window in which the HTML document containing the
JavaScript code currently being executed is open.

 The alert, confirm, and prompt methods display information in modal windows that block
access to the page until they are closed.

 You can call window methods, such as window.alert, without including the name
window, so calling alert(“abc”) would be correct.

 The alert, confirm, and prompt methods require an argument specifying the
position of the dialog box in which the information will be displayed.

14. The string “12” has been written into the str variable: (let str = “12”;). Then the
operation str = +str is performed. As a result, the variable str will contain:
 “+12”

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 12

 “12”

 NaN

JSE1: Module 4 Test Answers (JavaScript


Essentials 1)
November 10, 2022 JavaScript Essentials 1 Leave a comment

JavaScript Essentials 1 – JSE1: Module 4 Test Answers


1. Which sequence of if ... else statements is incorrect?
 if ... else if ...
 if ... else ... else if ...
 if ... else ...
 if ... else if ... else if...
2. Which of the following is not a loop instruction in JavaScript?
 for ... of
 for ... in
 if ... else
 do ... while
3. The condition if (!a) can be replaced by the condition:
 if (a == false);
 if (a === false);
 if (!!a);
 if (a);
4. Review the following code:
let x = 100;

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

if (x < 100)

x = 20;

console.log(x)

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


 20
 nothing

 100
 false
5. Review the following code snippet:
if (counter <= 10 && confirm === false) {

console.log("test");

What values can the counter and confirm variables have so that the console
displays "test" as a result of code execution?
 counter: 10 , show: true
 counter: 11 , show: false
 counter: 10 , show: false
 counter: 9 , show: true
6. The condition if( a >= 0 ) can be replaced by the condition:
 if (a > 0 || a == 0);
 if (!(a > 0 && a == 0));
 if (a > 0 && a == 0);
 if (0 < a);
7. Which of the following loop instructions is intended only to loop through all the
keys of the indicated object?
 for ... in
 do ... while
 for ... of

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 if ... else
8. Analyze the code below:
if (counter === 10) {

console.log("abc");

How can we write the same condition using the switch statement?
 switch(counter) {case 10: console.log("abc")};
 switch(counter) case 10: console.log("abc");
 case(counter) {switch 10: console.log("abc")};
 switch(counter) {case ? 10 : console.log("abc")};
9. We want to rewrite the following code snippet using the conditional operator:
let name;

if (test) {

name = 10;

} else {

name = 20;

Which notation is correct?


 let name = (test)("Alice")("Bob");
 let name = if test ? "Alice" : "Bob";
 let name = test ? "Alice" : "Bob";
 let name = test : "Alice" ? "Bob";
10. We store an array of animal names in the animals variable (e.g. let animals
= ["dog", "cat", "hamster", "rabbit"]; ). Which of the following
statements will display exactly two names from the array?
 for (let n in animals) console.log(n);

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 for (let i =3 ; i < animals.length; i++)


console.log(animals[i]);
 for (let i = 0; i < animals.length; i+=2)
console.log(animals[i]);
 for (let n of animals) console.log(n);
11. Which of the following operators is a ternary one?
 An increment operator ++ .
 A conditional operator ? : .
 A typeof operator.
 An assignment operator = .
12. Review the following code:
if (counter <= 10) {

if (counter >= 10) {

console.log(1);

We can replace it using:


 if (counter == 10) console.log(1);
 if (false) console.log(1);
 if (counter >= 10) console.log(1);
 if (true) console.log(1);
13. Examine the following code:
for (let a = 4; a < 4; a++) {

console.log("test");

How many times will "test" be displayed in the console as a result of its
execution?
 4

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 1

 It will not be displayed at all.

 3

14. Examine the following code:


let car = {make: "Citroen", model: "DS"};

for (let f in car) console.log(f);

What will appear on the console as a result?


 "make""model"
 "car"
 "make: Citroen" "model: DS"
 "Citroen" "DS"
15. Analyze the following code:
let a = 10;

do {

console.log(a--);

} while (a > 3);

Which statement can replace the do ... while from the example above?
 while (a > 2) console.log(--a);
 while (a > 4) console.log(--a);
 while (a > 3) console.log(a--);
 while (a >= 3) console.log(a--);
16. Analyze the following code:
for (let x = 10; x > 1; x -= 2) console.log("hello");

How many times will "hello" be displayed in the console as a result of its
execution?
 4

 9

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 5

 10

17. The switch statement:


 allows you to change the program mode to debug mode.

 is a conditional statement that allows different actions to be taken depending on


the value stored in the indicated variable.

 is a conditional statement that works identically to the if statement.


 is not present in the JavaScript language.

18. If we want to display all the elements of the days array in reverse order (starting
from the last element) then we can do this using the statement:
 for(let i = days.length; i > 0; i--) console.log(days[i]);
 for(let i = days.length - 1; i >= 0; i--)
console.log(days[i]);
 for(let i = days.length - 1; i > 0; i--)
console.log(days[i]);
 for(let i = days.length; i > 0; i--) console.log(i);
19. Examine the following code:
let steps = [3, 2, 1];

for (let n of steps) console.log(n);

What will appear on the console as a result?


 1 2 3
 "[3, 2, 1]"
 0 1 2
 3 2 1
20. Examine the following code:
for (let a = 5; a > 1; a--) {

console.log(a);

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

Which statement can replace the for from the example above?
 let a = 1; while (a < 5) console.log(a++);
 let a = 5; while (a > 1) console.log(a++);
 let a = 6; while (a >= 1) console.log(a--);
 let a = 5; while (a > 1) console.log(a--);

JSE1: Module 5 Test Answers (JavaScript


Essentials 1)
November 10, 2022 JavaScript Essentials 1 Leave a comment

JavaScript Essentials 1 – JSE1: Module 5 Test Answers


1. Analyze the following code:
let show = function () {

console.log(test);

setTimeout(show, 2000);

Its execution will cause:


 the console to display "test" after a 2 second delay.
 the console to display "test" after a 2000 second delay.
 the console to display "test" 2000 times.
 the console to display "show" after a 2 second delay.
2. Review the following code:
let x = 10;

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

let y = 20;

function test(y) {

console.log(y);

test(x);

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


 "y"
 20
 10
 Nothing, because the function expects the y variable to be passed and
receives x instead.
3. We define a function using the following function expression:
let sum = function (a, b) {

return (a + b);

What could the definition of the corresponding arrow function look like?
 let sum = function (a, b) => {

 return (a + b);

 }

 ;

 let sum = (a, b) => a + b;


 let sum = (a, b) > a + b;

 let sum = (a, b) => {

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 a + b;

 };

4. If the function is to return some calculated value on completion, we use the


following keyword to do so:
 yield;
 ret;
 function;
 return;

5. Analyze the code below:


function test(counter) {

console.log("test");

if (counter > 0)

test(--counter);

test(3);

How many times will the word "test" be displayed in the console?
 2

 4

 3

 0
6. A callback function is a function that:
 contains a reference to itself in its code.

 is always executed at fixed intervals.

 is always called with a certain pre-defined delay.

 is passed to another function as an argument and only called in its code.

7. Review the following code:

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

let x = 10;

function test(x) {

console.log(x);

test(20);

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


 Nothing will show up.

 "x"
 10
 20
8. We can use the forEach method to pass through the elements of an array. Which
of the following code snippets will display all consecutive elements of the animals
array in the console?
 animals.forEach(a => {

 console.log(a);

 })

 forEach(animals, a => {

 console.log(a);

 })

 animals.forEach(console.log(animal));
 animals.forEach(a => a);

9. We have defined an arrow function:


let multiply = (m, n) => m * n;

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

We will try to write it in a slightly modified form, but without changing what it is
supposed to do. Point out the correct definition:
 let multiply = (m, n) => {

 m * n;

 }

 let multiply = (m, n) => {

 console.log(m * n);

 }

 let multiply = (m, n) =>

 return (m * n);

 {

 return (m * n);

 }

10. The code snippet:


function test() {

is:
 the declaration of the test variable in which the values returned by the completed
function will be stored.
 the call of the test function.
 incorrect, as the code is wrong and does not mean anything.
 the declaration of an empty test function.
11. Analyze the following code:
let x = 10;

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

function test() {

let x = 20;

console.log(x);

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


 "x"
 20
 10

 Nothing will show up.

JSE1: Module 6 Test Answers (JavaScript


Essentials 1)
November 10, 2022 JavaScript Essentials 1 Leave a comment

JavaScript Essentials 1 – JSE1: Module 6 Test Answers


1. Which of the following is a syntax error?
 Attempting to call a non-existent function.

 Attempting to modify the value of a constant.

 Attempting to read a value from a variable that we have not previously declared.

 Missing parenthesis ending a condition in an if statement.


2. Analyze the code below:
"let x = 10";

What exception will be thrown as a result of its execution attempt?

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 TypeError

 RangeError

 SyntaxError

 ReferenceError

3. Where can we find in the debugger the information about the currently called
functions in our program?
 In the call stack window.

 In the console.
 We do not have access to such information.

 In the watch window.


4. Logical errors that we make while writing a program are not indicated by the
interpreter. Why?
 It results from the default settings of the interpreter, although we can modify these
settings so that logical errors are also pointed out.

 The interpreter does not indicate errors while the program is running, because it detects
them before the program runs (it does not allow the program to run).

 The interpreter ignores logical errors, because they do not affect the result of the
program in any way.

 The interpreter is unable to identify logical errors because they are not related to
either the syntax or the semantics of the JavaScript language.

5. Using the debugger, we insert a breakpoint in the code at which, after running the
program, we stop. In the debugger, we find a Step button among the step-by-step
operation options. What does pressing it do?
 Exactly one instruction immediately after the breakpoint will be executed and the
program will be paused again.

 The program will execute to the end or to the next breakpoint.

 The program will be restarted from the first instruction.

 The program will be executed to the end, regardless of whether there are more
breakpoints in the rest of the code or not.

6. Analyze the following code:


let x 10;

console.log(x);

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

What exception will be thrown as a result of its execution attempt?


 RangeError

 SyntaxError

 ReferenceError

 TypeError

7. Analyze the following code:


const x = 10;

x = 20;

What exception will be thrown as a result of its execution attempt?


 ReferenceError

 TypeError

 RangeError

 SyntaxError

8. We want to measure how long a certain piece of code executes. In order to do so, it
is enough to:
 precede the fragment with the command console.time("start") and end
with console.time("end") .
 precede the fragment with the command console.timeStart("counter") and
end with console.timeEnd("counter") .
 precede the fragment with the command timeStart() and end with timeEnd() .
 aprecede the fragment with the command console.time("counter") and
end with console.timeEnd("counter") .
9. What is the name of the place where program code execution is halted?
 exitpoint

 pausepoint

 breakpoint

 stoppoint

10. Analyze the following code:


try {

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

ocnsole.log("start");

} catch (error) {

console.log("error");

console.log("end");

What will happen as a result of its execution?


 The following words will appear in the console: "start" , "end" .
 The console will display the words "start" , "error" , "end" on successive
lines.
 The operation of the program will be interrupted and the console will display the default
message "Uncaught ReferenceError: ocnsole is not defined" .
 In the console, there will appear in successive lines the
words "error" , "end" .
11. Analyze the following code:
try {

ocnsole.log("start");

} catch (error) {

console.log("error");

} finally {

console.log("end");

What will happen as a result of its execution?


 The following words will appear in the console: "start" , "end" .
 The words "start" , "error" , "end" will appear in the console on successive
lines.
 The word "error" will appear in the console.

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 The following words will appear in the console: "error" , "end" .


12. Analyze the following code:
const x = 10;

onsole.log(x);

x += 10;

What exception will be thrown as a result of its execution attempt?


 SyntaxError

 ReferenceError and TypeError

 ReferenceError

 TypeError

13. Analyze the following code:


try {

console.log("start");

} catch (error) {

console.log("error");

} finally {

console.log("end");

What will happen as a result of its execution?


 The following words will appear in the console: "start" , "end" .
 The following words will appear in the console: "error" , "end" .
 The words "start" , "error" , “end” will appear in the console on successive
lines.
 The word "error" will appear in the console.
14. Analyze the following code:
let x = 10;

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

ocnsole.log(x);

What exception will be thrown as a result of its execution attempt?


 RangeError

 TypeError

 ReferenceError

 SyntaxError

JSE1 – Final Test Answers (JavaScript Essentials


1)
November 10, 2022 JavaScript Essentials 1 Leave a comment

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:

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 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);

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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 {

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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) {

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 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");

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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";

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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; };

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 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;

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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");

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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);

};

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

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);

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)


lOMoARcPSD|23010253

 clearInterval(interval);
 if (counter-- >= 0) clearInterval(interval);

Descargado por Fernando Pérez Mojica (ferperezm95@gmail.com)

You might also like