Quiz and Test Module 2
Quiz and Test Module 2
Índice
JAVASCRIPT ESSENTIALS 1 (JSE) - MODULE 2 .............................................................................................................................3
JAVASCRIPT ESSENTIALS 1 (JSE) MODULE 2 ........................................................................................................................................................... 3
Variables, Data Types, Type Casting, and Comments .......................................................................................................................... 3
QUIZ ....................................................................................................................................................................................................................4
TEST ...................................................................................................................................................................................................................9
• have the knowledge and skills to work with variables (i.e. naming, declaring, initializing and modifying
their values);
• understand concepts such as scope, code blocks, shadowing, and hoisting;
• know the basic properties of primitive data types such as boolean, number, bigint, undefined, null, and
be able to use them;
• be familiar with the basic properties of the primitive data type string, including string literals – single or
double quotes, the escape character, string interpolation, basic properties and methods;
• know the basic properties of complex data types such as Array and Object (treated as a record) and be
able to use them in practice.
The Number type allows the following values in addition to numeric values:
a. -OutOfRange, OutOfRange
b. -Infinity, Infinity, NaN, undefined
c. -Infinity, Infinity, NaN
d. -Infinity, Infinity, NaN, Unknown
We have declared an array: let animals = ["dog", "cat", "hamster"];. We want to temporarily
comment out the element "hamster", so for this we can modify the declaration as follows:
a. let animals = ["dog", "cat" #, "hamster"#];
b. let animals = ["dog", "cat"];
c. let animals = ["dog", "cat" /*, "hamster"*/];
d. let animals = ["dog", "cat" \\,"hamster”\\];
We want to declare a protocol constant and initialize it with the value "http”. What should such a
declaration look like?
a. let constant protocol="http";
b. const protocol="http";
c. let protocol; const protocol="http";
d. const protocol; protocol="http";
We perform the operation let x = le2 + 0×10;. As a result, the value of x is:
a. 27
b. NaN
c. 22
d. 116
Analyze the code snippet. Identify which variables are local and which are global.
let height;
let weight;
{
let age;
let sex;
{
let name;
}
}
global: height, weight
local: age, sex, name
We need to come up with a name for a variable where we will store the number of steps the user has
walked. All of the following variable names are formally correct, but one of them is the most readable -
indicate which one:
a. stepCounter
b. stepcounter
c. x
d. sc
Using the string interpolation technique, we can create the string "My favorite season is summer" and
store it in the msg variable using the command:
a. let season = "summer"; let msg = ‘My favourite season is ${season}’;
b. let season = "summer"; let msg = ‘My favourite season is “season”’;
c. let season = "summer"; let msg = "My favourite season is \{season\}";
d. let season = "summer"; let msg = ‘My favourite season is ${season}’;
In the summer variable, we have stored an array with the names of the selected months: let summer =
["June", "July", "August"];
We want to check if there is an element "August" in the array and determine its position (index). To do
so, we call:
a. summer.index0f("August"):
b. summer.index0f(August);
c. summer.index("August");
d. index of "August" in summer;
We have declared an array of animals: let animals = ["dog", "cat", "hamster"];. Then we call
the method animals.unshift("canary"); As a result, the animals array will look like this:
a. ["canary", "dog", "cat", "hamster"]
b. [“dog”, "cat", "hamster", "canary"]
c. ["canary"]
d. ["dog", "cat", "hamster"]
We want to convert the number 1024 to a String type and store the result in the variable s . Point out the
correct statement:
a. let s = String(1024);
b. let s = Number(1024);
c. let g = 1024+"0";
d. let g = NumberToString(1024);
We have initialized the name variable with the value "Alice", then we try to write the number 100 into it.
let name = "Alice";
name = 100;
As a result of this:
a. the variable will retain the value "Alice" (we cannot modify the value that the variable has been
initialized with).
b. the variable will contain the string "100"
c. the variable will contain the number 100.
d. the program will be aborted due to an error (we are trying to insert a value of a different type into the
variable than the value with which it was initialized).
We define an object that will contain one field with the key name. We will place the value "Bob" in this
field and store the object in the variable obj. Indicate the correct declaration:
a. let obj = name:"Bob"
b. let obj = name.Bob;
c. let obj = name:(“Bob");
d. let obj = (name:"Bob");
In the animals variable, we store an array of animal names. We want to enlarge this array by appending
elements of the otherAnimals array to it. To do this, we can call the command:
a. animals.concat(otherAnimals);
b. otherAnimals.concat(animals);
c. animals.merge (otherAnimals);
d. animals=animals.concat(otherAnimals);
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:
a. place the "prevent undeclared variables"; directive at the beginning of the script.
b. perform all writes to variables in a block of code delimited by braces.
c. place the "use strict"; directive at the beginning of the script.
d. place the "use strict"; directive before each write we want to protect.
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:
a. ["cat", "hamster"]
b. ["dog", "cat"]
c. ["hamster"]
d. ["dog", "cat", "hamster"]
The msg variable contains a String type value. Information about the number of characters of this string
can be obtained using:
a. msg.chars
b. msg.length
c. msg.length()
d. msg.charsAt()
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:
a. user
b. userAge
c. age
d. ua
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
a. summer [1] = 7;
b. summer [0] = 7;
c. summer.July = 7;
d. We cannot do this (an array can only contain elements of the same type).
We want to convert the string "1024" to type Number and store the result in variable n . Point out the
correct statement:
a. let n = "1024” + 0;
b. let n = String ("1024");
c. let n = StringToNumber ("1024");
d. let n = Number ("1024");
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:
a. let animals = ["dog", #"cat", # "hamster"];
b. let animals = ["dog", //"cat", // "hamster"];
c. let animals = ["dog", "hamster"];
d. let animals = ["dog", /*"cat", */ "hamster");
Analyze the code snippet. Identify which variables are local and which are global:
let name
let age:
{
let profession
{
let height;
let weight;
}
a. name
b. profession
c. age
d. height
e. weight
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:
a. invert(daysOfWeek);
b. daysOfWeek.invert();
c. reverse daysOfWeek;
d. daysOfWeek.reverse();