Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

JavaScript Essentials 1

Uploaded by

wei chen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

JavaScript Essentials 1

Uploaded by

wei chen
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Question 1

Multiple choice question

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

generate and load a minimal blank HTML page into the current tab.
clear all inputs on the current page.
generate a page with information about the browser's status.
open a tab with information about your browser.
Error! Filename not specified.
Completed Question 2

Question 2
Multiple choice question

Analyze the following code:

1
2
3
4
5
6
let id = "100";
{
let id = 200;
id = id + 1;
console.log(id);
}

What will appear to the console as a result?

201
101
1001
200
Error! Filename not specified.
Completed Question 3

Question 3
Multiple choice question

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

Array, Object
Array, Object, String
Object, String
Boolean, Number, Bigint
Error! Filename not specified.
Completed Question 4
Question 4
Multiple choice question

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

let x = 0.003;
let x = 3000;
let x = 0.0003;
let x = 0.333;
Error! Filename not specified.
Completed Question 5

Question 5
Multiple choice question

Using the string interpolation technique, we can create the string:

1
"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 \}';
Error! Filename not specified.
Completed Question 6

Question 6
Multiple choice question

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

1
2
3
let movie = {
title: "Life",
year: 1999

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


movie.title = "Matrix";
title->movie = "Matrix";
movie{title} = "Matrix";
movie[title] = "Matrix";
Error! Filename not specified.
Completed Question 7

Question 7
Multiple choice question

You declare the following array of animals: let animals = ["canary", "dog", "cat"];. Then,
you call the method animals.push("hamster");. What will the animals array look like after
calling the method?

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


["hamster"]
["hamster", "canary", "dog", "cat"]
["canary", "dog", "cat"]
Error! Filename not specified.
Completed Question 8

Question 8
Multiple choice question

A JavaScript code includes the console.log("http://somethingNew.org"); command. Its


execution will:

display the following message on the console: "http://somethingNew.org".


display on the console information about the progress of
the http://somethingNew.org page loading.
cause the page http://somethingNew.org to be loaded into the browser.
send a log with information about the currently executed script to the indicated
address http://somethingNew.org.
Error! Filename not specified.
Completed Question 9

Question 9
Multiple choice question

Analyze the code snippet:

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

What value will the index variable have?

2
1
"February"
3
Error! Filename not specified.
Completed Question 10

Question 10
Multiple choice question

In the daysOfWeek variable, you place an array with the names of the days of the week.
Which method will you call to reverse the order of the array elements.

daysOfWeek.reverse();
daysOfWeek = reverse(daysOfWeek);
daysOfWeek.invert();
daysOfWeek.order(-1);
Error! Filename not specified.
Completed Question 11

Question 11
Multiple choice question

Review the following code:

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

What will appear on the console as a result?

o
h
ohello
hello
Error! Filename not specified.
Completed Question 12

Question 12
Multiple choice question

Analyze the following code:

1
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
Run
OK
true
Error! Filename not specified.
Completed Question 13

Question 13
Multiple choice question

Analyze the following code:

1
2
3
4
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?

true false false


false false true
false false false
false true true
Error! Filename not specified.
Completed Question 14

Question 14
Multiple choice question

Analyze the following code:

1
2
3
4
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?

20 20 0
110
true 20 0
true true false
Error! Filename not specified.
Completed Question 15

Question 15
Multiple choice question

Examine the following code:

1
2
3
4
5
6
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?

2010, 30, 1010, 0100, NaN


2010, 2010, 20-1010, 0100, NaN
30, 31, 39, 100, NaN
30, 30, 20, 100, 2
Error! Filename not specified.
Completed Question 16

Question 16
Multiple choice question

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

do ... while
while
for ... in
for
Error! Filename not specified.
Completed Question 17

Question 17
Multiple choice question

The following function using a function expression has been defined:


1
2
3
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 = (a, b)-- > a + b;
let sum = function (a, b) => {
return (a + b); }
Error! Filename not specified.
Completed Question 18

Question 18
Multiple choice question

The temp array contains air temperature data measured over a period of time. You want
to display the minimal temperature using the following code:

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

What should the declaration of the min variable look like?

let min = temp[0];


let min = 0;
let min;
It’s not necessary, as it will be declared automatically on first use.
Error! Filename not specified.
Completed Question 19

Question 19
Multiple choice question

Examine the following code:

1
2
3
4
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?

5
6
4
2
Error! Filename not specified.
Completed Question 20

Question 20
Multiple choice question

Analyze the following code:

1
2
3
for(let a=1; a<10; a+=2) {
console.log(a);
};

Which statement can replace the for from the example?

let counter = 0;
while (counter++ < 10) console.log(counter++);
let counter = 1;
while (counter++ < 10) console.log(counter++);
let counter = 0;
while (counter < 10) console.log(counter++);
let counter = 0;
while (counter < 9) console.log(counter++);
Error! Filename not specified.
Completed Question 21

Question 21
Multiple choice question

Analyze the following code:

1
2
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
['red', 'green', 'blue']
0
1
2
3
Error! Filename not specified.
Completed Question 22

Question 22
Multiple choice question

Analyze the following code:

1
2
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
elevation
131
1.4
distance
2
Error! Filename not specified.
Completed Question 23

Question 23
Multiple choice question

Examine the following code:

1
2
3
4
let a = (n) => {
return n > 2 ? n * a(n - 1) : 2
}
console.log(a(6));

What will appear on the console as a result?

720
120
6
4
Error! Filename not specified.
Completed Question 24

Question 24
Multiple choice question

Examine the following code:

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


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

Question 25
Multiple choice question

Analyze the code snippet:


1
2
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
Error! Filename not specified.
Completed Question 26

Question 26
Multiple choice question

Examine the following code:

1
2
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) => a - b;


let cmp = (a, b) => b - a;
let cmp = (a, b) => b < a;
let cmp = (a, b) => b > a;
Error! Filename not specified.
Completed Question 27

Question 27
Multiple choice question

Analyze the following code, which is missing one line:

1
2
3
4
5
let counter = 2;
let interval = setInterval(() => {
console.log(counter);
// Insert missing line here.
}, 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);


if (counter-- >= 0) clearInterval(interval);
clearInterval(interval);
while (counter-- >= 0) clearInterval(interval);
Error! Filename not specified.
Completed Question 28

Question 28
Multiple choice question

Analyze the following code:

1
2
3
4
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 = (x, y) => x ** y;


let power = () => a ** b;
let power = (x,y) => x * y;
let power = 9;
Error! Filename not specified.
Completed Question 29

Question 29
Multiple choice question

Analyze the following code:

1
2
3
4
5
6
7
8
const a = "hello";
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 on subsequent lines: HELLO and hello.
The following words will appear in the console on subsequent lines: hello and hello.
The following word will appear in the console: HELLO.
The following words will appear in the console on subsequent
lines: HELLO, hello, and hello.
Error! Filename not specified.
Completed Question 30

Question 30
Multiple choice question

Placing a debugger; statement in the program code will:

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".
put the interpreter into report mode, which will cause the console to print out all
sequentially executed commands.
cause the console to display the completion status of the statement preceding the
debugger.
Error! Filename not specified.
You've submitted your answers!
Reset

You might also like