0% found this document useful (0 votes)
918 views13 pages

Quiz and Test Module 2

Test Python

Uploaded by

josegmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
918 views13 pages

Quiz and Test Module 2

Test Python

Uploaded by

josegmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Quiz and Test (JSE) Module 2

Centro público integrado de formación profesional


Nuevo (desglose IES Campanillas)

Quiz and Test


JavaScript Essentials 1 (JSE)
Module 2

José García JavaScript - JSE-40-01


Quiz and Test (JSE) 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

José García 2 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
JavaScript Essentials 1 (JSE) - Module 2

JavaScript Essentials 1 (JSE)


Module 2

Variables, Data Types, Type Casting, and Comments


After completing Module 2, the student will:

• 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.

José García 3 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
Quiz
We declare an array consisting of the names of selected months and store them in the variable summer.
Which declaration is correct?
a. let summer = {“June", "July", "August"');
b. let summer = "June", "July", "August";
c. let summer[0, 1,2] = "June", "July", "August";
d. let summer = [ "June", "July", "August"];

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

What operator do we use to check the type of a variable?


a. type
b. variabletype
c. typeof
d. showtype

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 following code:


let height;
console.log (height);
Executing it will:
a. display the message "height" in the console.
b. display the null value in the console.
c. cause the program to terminate with an error because we are referring to a variable that has no value.
d. display the undefined value in the console.

José García 4 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
Analyze the code snippet:
let distance = 0;
let userName = "John";
After declaring the distance 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:
a. let distance = 0; /* the distance the user has walked */
b. let distance = 0; ## the distance the user has walked
c. let distance = 0; /* the distance the user has walked
d. // let distance = 0; the distance the user has walked

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

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 height variable:
a. throughout the program.
b. nowhere, as we have no access at all (the variable has not been initialized).
c. in the part marked 2.
d. in the part marked 1.

Analyze the code snippet:


let summer = [ "June", "July", "August"1];
let index = summer.indexOf("May") ;
The index variable will have the value:
a. 0
b. -1
c. false
d. undefined

José García 5 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
We have declared an array of animals: let animals = ['dog", "cat", "hamster"];. Then we call
the method animals.shift();
As a result, the animals array will look like this:
a. ["cat", "hamster"]
b. ["dog", "cat"]
c. ["dog", "cat", "hamster"]
d. ["'dog"]

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

Review the following code (note the variable name)


let height = 170;
height = height + 10;
console.log (Height);
As a result of its execution, the following should appear in the console:
a. 170
b. 180
c. error message "Uncaught ReferenceError: Height is not defined"
d. "Height"

We perform the operation let x = "abcdefg".slice(2). As a result, the value:


a. “c" will be written to the variable ×.
b. “ab" will be written to the variable ×
c. [“ab", "cdefg"] will be written to the variable x.
d. "cdefg" will be written to the variable x.

Analyze the following code:


let height = 180;
{
let height = 200;
height = height + 10;
console.log (height);
}
As a result of its execution:
a. a value of 180 will be displayed in the console.
b. a value of 210 will be displayed in the console.
c. a value of 200 will be displayed in the console.
d. the program will be terminated due to an error (a re-declaration of the height variable).

José García 6 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
Adding the suffix ...n to the end of a number, e.g. 100n, means that:
a. it is a value of the Number type written in decimal format.
b. it is a value of an unspecified type.
c. it is an integer of type Number.
d. it is a value of the Biglnt type.

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 can replace the declaration let x = 2e4; with:


a. let x = 24:
b. let x = 24000;
c. let x = 0.0002;
d. let x = 20000;

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

A local variable is a variable:


a. that can only be used in a program executed on a local machine.
b. whose scope of visibility is limited only to a fragment of the program, e.g. inside a function.
c. that is visible in the whole program code, but we can modify it only in a specific part of the program, for
example, inside a function.
d. that we cannot modify.

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 declared an array of names:


let names = ["Olivia", "Emma", "Mia", "Sofia*];
We want to display the name "Emma" on the console, and to do this we call:
a. console.log(names(2});
b. console.log(names[2]);
c. console.log(names.Emma);
d. console.log(names[1]);

Point out the correct declaration of the temperature variable:


a. variable temperature,
b. declare temperature;
c. temperature is variable;
d. let temperature;

José García 7 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
Which of the following declarations using the String type is incorrect?
a. let msg = 'The vessel "Mars" called at the port';
b. let msg = "The vessel "Mars" called at the port";
c. let msg = "The vessel 'Mars' called at the port";
d. let msg = "The vessel \"Mars\" called at the port";

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

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


a. Array, Boolean, Number, String.
b. Boolean, Number, Bigint, String.
c. Array, Boolean, Number, Bigint, String.
d. Array, Object.

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

José García 8 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
Test
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:
a. age of dog = 6;
b. dog (age] = 6;
c. dog.age = 6;
d. dog [age] = 6;

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:
a. let counter = 0; # user visit counter
b. let counter = 0; /* user visit counter
c. let counter = 0; // user visit counter
d. // let counter = 0; user visit counter

What does shadowing mean?


a. Deleting and rewriting a selected piece of program code.
b. Changing the value of a variable.
c. Declaring a local variable with the same name as the previously declared global variable.
d. Declaring a global variable with the same name as a previously declared global variable.

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.

Performing the operation: let x = 20 + 10; will result in:


a. result in a value of 30n being stored in the variable x .
b. result in the string "20n10" being stored in the variable x .
c. result in a value of 30 being stored in the variable x
d. cause the program to abort due to an error.

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

José García 9 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
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:
a. ["dog", "cat", "hamster", "canary"]
b. ["canary"]
c. ["dog", "cat", "hamster"]
d. ['canary", "dog", catm, "hamster"]

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


a. is of the Logical type.
b. is of the Boolean type.
c. will no longer be used in the program.
d. is of the Math type.

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

Performing the operation: let × = "Alice" + 10; will result in:


a. the value "Alice10" of String type to be stored in the variable *
b. the program execution to abort due to an error.
c. the value NaN of Number type to be stored in the variable x
d. the value 15 of Number type to be stored in the variable x

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

Analyze the following code:


let height = 180;
{
let height = 200;
height = height + 10;
}
console.log(height);
As a result of its execution:
a. a value of 180 will be displayed in the console.
b. the program will be terminated due to an error (re-declaration of the height variable).
c. a value of 200 will be displayed in the console.
d. a value of 210 will be displayed in the console.

Analyze the following code:


let x = 10 / 100;
console.log (typeof (x));
As a result of its execution:
a. it will display "number" in the console.
b. it will display "fraction" in the console.
c. it will display 0.1 in the console.
d. an error will appear because JavaScript does not allow operations on fractional numbers.

José García 10 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
We want to declare a distance constant and initialize it with the value 120.
What should such a declaration look like?
a. const distance = 120;
b. const distance; distance = 120;
c. let constant distance = 120;
d. let distance; const distance = 120;

We perform the operation: let x = "abcdefg".slice(2, 4). As a result, the value:


a. "ab" will be written to the variable x
b. radef" will be written to the variable x
c. " cde£g" will be written to the variable x
d. "cd" will be written to the variable x

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:
a. 33
b. 32
c. undefined
d. error message: "Uncaught ReferenceError: Age is not defined"

In order to check the number of elements of the array stored in the


names variable, we call:
a. names. count
b. length of names;
c. names. length ();
d. names. Length

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


a. let x = 17;
b. let x = 33;
c. let x = "0x21"
d. let x = 21;

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

José García 11 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
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:
a. nowhere, as we have no access at all (the variable has not been initialized).
b. in the part marked 1.
c. in the part marked 2.
d. throughout the program.

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

Point out the correct declaration of the height variable:


a. height is variable;
b. let height;
c. height;
d. variable height;

Complex (or composite) data types:


a. is an alternative name for primitive types.
b. may consist of multiple elements, each of which may be of a primitive or composite type.
c. are not used in JavaScript.
d. may consist of multiple elements, each of which is of a primitive type.

Analyze the following code:


let counter = 100;
let counter = 200;
counter = 300;
As a result of its execution:
a. the counter variable will have the value 200.
b. the program will be aborted due to an error (redeclaration of a variable).
c. the counter variable will have the value 300.
d. the counter variable will have the value 100.

José García 12 JavaScript - JSE-40-01


Quiz and Test (JSE) Module 2
Analyze the code snippet:
let summer = ["June", "July", "August"]:
let index = summer. indexOf ("June");
The index variable will have the value:
a. 0
b. "June"
c. True
d. 1

Performing the operation: let x = 100 / 0; will:


a. the value 0 being stored in the variable x.
b. the value NaN being stored in the variable x.
c. an undefined value being stored in the variable x.
d. an Infinity value being stored in the variable x.

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

José García 13 JavaScript - JSE-40-01

You might also like