Quiz
JavaScript
Crie uma conta grátis para terminar este quiz
Salve seu progresso e veja sua nota final.
Já tem uma conta? Inicie sessão
Perguntas do quiz (108)
1Inside which HTML element do we put the JavaScript?
- A<javascript>
- B<scripting>
- C<js>
- D<script>
2What is the correct syntax for referring to an external script called "xxx.js"?
- A<script src="xxx.js">
- B<script href="xxx.js">
- C<script name="xxx.js">
3The external JavaScript file must contain the <script> tag.
- ATrue
- BFalse
4How do you write "Hello World" in an alert box?
- AalertBox("Hello World");
- BmsgBox("Hello World");
- Calert("Hello World");
- Dmsg("Hello World");
5How do you create a function in JavaScript?
- Afunction = myFunction()
- Bfunction myFunction()
- Cfunction:myFunction()
6How do you call a function named "myFunction"?
- AmyFunction()
- Bcall myFunction()
- Ccall function myFunction()
7How to write an IF statement in JavaScript?
- Aif i = 5 then
- Bif i = 5
- Cif (i == 5)
- Dif i == 5 then
8How to write an IF statement for executing some code if "i" is NOT equal to 5?
- Aif i =! 5 then
- Bif (i != 5)
- Cif (i <> 5)
- Dif i <> 5
9How does a FOR loop start?
- Afor (i = 0; i <= 5; i++)
- Bfor (i <= 5; i++)
- Cfor (i = 0; i <= 5)
- Dfor i = 1 to 5
10What is the correct way to write a JavaScript array?
- Avar colors = "red", "green", "blue"
- Bvar colors = (1:"red", 2:"green", 3:"blue")
- Cvar colors = ["red", "green", "blue"]
- Dvar colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")
11What is the correct JavaScript syntax for opening a new window called "w2" ?
- Aw2 = window.open("http://www.w3schools.com");
- Bw2 = window.new("http://www.w3schools.com");
12JavaScript is the same as Java.
- ATrue.
- BFalse.
13How can you detect the client's browser name?
- Abrowser.name
- Bnavigator.appName
- Cclient.navName
14How do you declare a JavaScript variable?
- Av carName;
- Bvariable carName;
- Cvar carName;
15Which operator is used to assign a value to a variable?
- A-
- B=
- Cx
- D*
16What will the following code return: Boolean(10 > 9)
- ANaN
- Btrue
- Cfalse
17Is JavaScript case-sensitive?
- AYes
- BNo
18Where is the correct place to insert a JavaScript?
- AThe <head> section
- BThe <body> section
- CBoth the <head> section and the <body> section are correct
19How does a WHILE loop start?
- Awhile (i <= 10; i++)
- Bwhile i = 1 to 10
- Cwhile (i <= 10)
20How can you add a comment in a JavaScript?
- A//This is a comment
- B<!--This is a comment-->
- C'This is a comment
21Which event occurs when the user clicks on an HTML element?
- Aonmouseclick
- Bonchange
- Conmouseover
- Donclick
22What is the correct JavaScript syntax to change the content of the HTML element below?
<p id="demo">This is a demonstration.</p>- A#demo.innerHTML = "Hello World!";
- Bdocument.getElementById("demo").innerHTML = "Hello World!";
- Cdocument.getElementByName("p").innerHTML = "Hello World!";
- Ddocument.getElement("p").innerHTML = "Hello World!";
23How to insert a comment that has more than one line?
- A//This comment has
more than one line// - B<!--This comment has
more than one line--> - C/*This comment has
more than one line*/
- A//This comment has
24How do you round the number 7.25, to the nearest integer?
- Around(7.25)
- Brnd(7.25)
- CMath.rnd(7.25)
- DMath.round(7.25)
25How do you find the number with the highest value of x and y?
- AMath.max(x, y)
- Bceil(x, y)
- CMath.ceil(x, y)
- Dtop(x, y)
26Given a number of elements that need to stay in order, would you use an Object or an Array?
- AObject
- BArray
27Given a collection of artists and lists of their songs, would you store the artist-song-list pairs in an Object or an Array?
- AObject
- BArray
28True or false: All the elements in an array must be of the same type.
- ATrue
- BFalse
29True or false: All keys in an object are strings.
- ATrue
- BFalse
30What happens to the array in the following code snippet?
const dogs = ["Fido", "Odie", "Oscar"]
dogs.length
dogs.length = 1- ANothing
- BThe array becomes just ["Oscar"]
- CThe array becomes just ["Fido"]
- DThe array becomes just ["Odie", "Oscar"]
31What are the keys in the object after running the code below?
const artistsAndSongs = {
'Prince': ["Purple Rain", "When Doves Cry"],
'The Beatles': ["Revolution", "Norwegian Wood"],
'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
'Justin Bieber': ["Baby"]
}
artistsAndSongs['Daft Punk'] = ["Harder, Better, Faster, Stronger"]
delete artistsAndSongs["Justin Bieber"]- A['Prince', 'The Beatles', 'Joni Mitchell', 'Justin Bieber', 'Daft Punk']
- B['Prince', 'The Beatles', 'Joni Mitchell', 'Justin Bieber']
- C['Prince', 'The Beatles', 'Joni Mitchell']
- D['Prince', 'The Beatles', 'Joni Mitchell', 'Daft Punk']
32If we run artistsAndSongs['Daft Punk'].push("Around the World") after running the code below, what is the value of the object?
const artistsAndSongs = {
'Prince': ["Purple Rain", "When Doves Cry"],
'The Beatles': ["Revolution", "Norwegian Wood"],
'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
'Justin Bieber': ["Baby"]
}
artistsAndSongs['Daft Punk'] = ["Harder, Better, Faster, Stronger"]
delete artistsAndSongs["Justin Bieber"]- Aconst artistsAndSongs = {
'Prince': ["Purple Rain", "When Doves Cry"],
'The Beatles': ["Revolution", "Norwegian Wood"],
'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
'Daft Punk': ["Harder, Better, Faster, Stronger"]
} - Bconst artistsAndSongs = {
'Prince': ["Purple Rain", "When Doves Cry"],
'The Beatles': ["Revolution", "Norwegian Wood"],
'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
'Daft Punk': ["Harder, Better, Faster, Stronger", "Around the World"]
} - Cconst artistsAndSongs = {
'Prince': ["Purple Rain", "When Doves Cry"],
'The Beatles': ["Revolution", "Norwegian Wood"],
'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
'Daft Punk': ["Around the World"]
} - Dconst artistsAndSongs = {
'Prince': ["Purple Rain", "When Doves Cry"],
'The Beatles': ["Revolution", "Norwegian Wood"],
'Joni Mitchell': ["A Case of You", "Sunny Sunday"]
}
- Aconst artistsAndSongs = {
33What is the result of the following code in a browser that supports the spread operator?
const oneTwoThree = [1, 2, 3]
const sevenEightNine = [7, 8, 9]
[4, 5, 6, ...oneTwoThree, ...sevenEightNine]- A[4, 5, 6, 7, 8, 9, 1, 2, 3]
- B[4, 5, 6, 1, 2, 3, 7, 8, 9]
- C[1, 2, 3, 4, 5, 6, 7, 8, 9]
- DError
34Given the array const letters = ["alpha", "gamma", "delta"], which operation(s) return the array ["alpha", "beta", "gamma", "delta"]?
- Aletters.push("beta")
- Bletters.unshift('beta')
- C[...letters.slice(0, 1), 'beta', ...letters.slice(1)]
- Dletters.splice(1, 1, 'beta')
- Eletters.splice(1, 0, 'beta')
35What does the following function call log to console:
function log() {
console.log(greeting);
var greeting = 'Hello!';
}
log();- A'Hello!'
- Bundefined
- C'undefined is not a function'
36What does the following function call log to console:
log();
function log() {
console.log(greeting);
var greeting = 'Hello!';
}- A'Hello!'
- Bundefined
- C'undefined is not a function'
37What does the following function call log to console:
log();
var log = function() {
console.log(greeting);
var greeting = 'Hello!';
}- A'Hello!'
- Bundefined
- C'log is not a function'
38What does the following function log to console:
function log(s) {
var s = 'Mr. X';
console.log(s);
}
log('Hello!');- A'Hello!'
- B'Mr. X'
- Cundefined
- D'undefined is not a function'
39Which of the following is/are strings?
- A4
- B4.0
- C'4'
40Which of the following is/are numbers?
- A4
- B4.0
- C'4'
- D-4
41Which of the following is/are booleans?
- Atrue
- Bfalse
- C"true"
42What is the result of 80 + 71.2?
- A151.2
- B151
- C8071.2
43What is the result of "80" + 71.2?
- A151.2
- B151
- C"8071.2"
44What is the result of 2 + "2"?
- A4
- B"4"
- C"22"
45Does 100 + 30 produce a number or a string?
- ANumber
- BString
46Does "100" + 30 produce a number or a string?
- Anumber
- Bstring
47Which of the following is the correct way of returning the length of this string?
- A'string',length
- Bstring,length
- Cstring.length
- D'string'.length
48Which of the following will correctly comment the text?
- A// “the text” //
- B/ “the text” /
- C*/ “the text” /*
- D\\ “the text” \\
49Which of the following is the correct use of the confirm dialog?
- Aconfirm. “Hello world”;
- Bconfirm(“Hello world”);
- Cconfirm.(“Hello world”);
- Dconfirm[“Hello world”];
50Which of the following is the correct way to log a statement to the console?
- Aconsolelog("Hello world")
- Bconsole.log("Hello world")
- Cconsole.log{"Hello world"}
51Which of the following is not a comparator operation in JavaScript?
- A<==
- B!==
- C===
- D>
52What follows after the expression in an if statement?
- Acurly braces
- Ba colon
- Csquare brackets
- Dbrackets
53Which of the following statements returns false?
- A'myName'.length > 2
- B3 * 4 < 15
- C4 / 2 == 2
- D'inputControl'.length < 4
54What is the substring keyword used for?
- ACreating a string within a string
- BReturning a partial part of a string
- CReordering characters in a string
- DSubstituting characters within a string
55Which of the following best describes what a function in JavaScript is used for?
- AA function creates new variables
- BA function is used for math formulas
- CA reusable piece of code that can be called on throughout an application
- DA function allows for the use of mathematical operators
56The input in a function is called?
- Afunction variable
- Bparameter
- Creturn
- Dglobal variable
57 Which of the following demonstrates correct syntax for a function?
//1 var myFunction = function[] {};
//2 var myFunction = function() {};
//3 var myFunction = function{} ();
//4 var myFunction = function(); {};- A1
- B2
- C3
- D4
58Which of the following the correct way to call the function below?
var multiplier = function(number) {
console.log(3 * number);
};- Amultiplier 5 ;
- Bmultiplier{5};
- Cmultiplier(5);
- Dmultiplier[5];
59Which of the following correctly calls this function?
var input = prompt("Enter input value");
var controlVal = input / 2 + 3;
var multiplier = function(number, phase) {
var val = number * controlVal + phase;
console.log(val);
};- Amultiplier(2, 1);
- Bnumber(2);
- Cnumber(2, 1);
- Dmultiplier(2);
60Which of the following is the end condition for this for loop?
for (var condition = 0; condition < 5; condition ++) {
return condition;
};- Acondition = 0
- Bcondition ++
- Creturn condition
- Dcondition < 5
61Which of the following is the start condition for this for loop?
for (var condition = 0; condition < 5; condition ++) {
return condition;
};- Acondition = 0
- Bcondition ++
- Creturn condition
- Dcondition < 5
62What best describes the function of a for loop?
- AIt loops through a block of code by a determinable amount of loops
- BIt looks for a loop in a block of code
- CIt loops through code only within a function
- DIt loops through a block of code by an undeterminable amount of loops
63What does this for loop do?
for (var i = 2; i <= 7; i++) {
console.log(i);
};- Aprints i seven times
- Bprints the numbers 1 to 7
- Cprints the numbers 2 to 6
- Dprints the numbers 2 to 7
64Which of the following for loops prints the block of code below?
//0 5 10 15 20 25
//Scroll down
//1 for (var i = 1; i <= 25; i+= 5) {
console.log(i);
};
//2 for (var i = 0; i < 28; i += 5) {
console.log(i);
};
//3 for (var i = 0; i < 25; i =+ 5) {
console.log(i);
};
//4 for (var i = 0; i <= 25; i =+ 5) {
console.log(i);
};- A1
- B2
- C3
- D4
65Which of the following best describes an array?
- AA variable that can create functions
- BA variable that can store a list of different data seperately
- CA data type that can store data
- DA data type that can create functions
66Which of the following uses correct array syntax?
- Avar array = [ 5; 6; “hello”];
- Bvar array = [ 5, 6, “hello”];
- Cvar array = { 5, 6 ,“hello”};
- Dvar array = { 5; 6; “hello”};
67Which of the following will return “hello” from the array below?
var array = [ 5, 6, “hello”, 2, false];- Aarray(2)
- Barray[3]
- Carray(3)
- Darray[2]
68Which of the following will print all element of the array below with exception to Melbourne and Paris?
var cities = ["Melbourne", "Amman", "Helsinki", "NYC", "London", "Dhaka", "Paris"];
//Scroll down
//1 for (var i = 0; i < 6; i++) {
console.log(cities[i]);
};
//2 for (var i = 1; i < 6; i++) {
console.log(cities[i]);
};
//3 for (var i = 1; i <= 5; i++)
console.log(cities[i]);
};
//4 for (var i = 0; i <= 5; i++) {
console.log(cities[i]);
};- A1
- B2
- C3
- D4
69 Which of the following best describes an element in JavaScript?
- Athe number of entries in an array
- Bthe data type for an array
- Cthe name of an array
- Dan entry in an array
70How are while loops different to for loops?
- AThe start of the loop is not predefined in while loops
- BWhile loops cannot use comparison operators
- CThe end of the loop is not predefined
- DThe control of the loop is not predefined in for loops
71What will happen if an infinite while loop is ran in javascript?
- AThe program will crash
- BThe computer will crash
- CThe while loop will run as normal
- DAn error message will be displayed
72Which of the following is an infinite loop?
//Scroll down
//1 var i = 1;
while(1 < 4) {
console.log("loading…");
i = i + 1
};
//2 var i = 1;
while(1 = 4) {
console.log("loading…");
};
//3 var i = 1;
while(1 = 4) {
console.log("loading…");
i = i + 1
}
//4 var i = 1;
while(1 < 4) {
console.log("loading…");
};- A1
- B2
- C3
- D4
73Which of the following cases should be implemented using a while loop?
- AReturn the number of times a coin is tossed until it is heads
- BSum the numbers from 1 to 10
- CCount down from 100 to 0
- DReturn the number of times coin lands on head when it is tossed 10 times
74The following while loop is an infinite loop, what should the line below be replaced with?
var check = true;
var loopCheck = function(check){
while(check){
console.log("Looped once!");
____________
}
}- AloopCheck = false;
- Bcheck = “false”;
- CloopCheck = “false”;
- Dcheck = false;
75What is the use of the isNaN function?
- AIt converts a string of numbers to a number
- BIt checks if something is not a number and returns a boolean
- CIt checks if something is a number and returns a boolean
- DIt converts a number to a string
76Which of the following returns false?
- AisNaN(“Hey!”);
- BisNaN(“23”);
- CisNaN(false);
- DisNaN(true);
77What best describes a case in a switch statement?
- AIt transfers control by matching the output expression with the case expression
- BIt transfers control by matching the case expression with the input expression
- CIt transfers control by matching the case expression with the output expression
- DIt transfers control by matching the input expression with the output expression
78In which of the following situations will the default case in a switch statement be executed?
- AOnly when the input is the string "default"
- BOnly when no entry is made in the prompt dialog
- CWhen an input doesn't have a corresponding case
- DWhen an input isn’t a string
79The block of code bellow is used to prompt the user for an input, what will be the first line of the corresponding switch statement?
var answer = prompt("Enter here");
var message = "You have selected " + answer;
console.log(message);- Aswitch (answer) {
- Bswitch {message} (
- Cswitch {'answer'} (
- Dswitch ('message') {
80Which of the following is not a logical operator in JavaScript?
- A||
- B&&
- C!
- D$$
81Which of the following is the symbol for implementing the AND operator?
- A||
- B&&
- C$$
- D!
82Which of the following is the symbol for implementing the OR operator?
- A||
- B&&
- C$$
- D!
83What would you replace the comment below with to print 'Hey!' to the console?
//Replace this comment
var check = false;
if (check || input) {
console.log(‘Hey’);
}- Anameinput = true;
- Bvar check = true;
- Cvar input = true;
- Dvar input = ‘true’;
84What will be printed to the console when the following block of code in run in the editor?
var print = ‘Hi. My name is Leng’.toLowerCase();
console.log(print);- A“i. y name is eng"
- B“hi. my name is leng”
- C“HI, MY NAME IS LENG”
- D“Hi. My name is Leng”
85What is the correct format for declaring a function in Javascript?
- Afunction foo(){...}
- Bfoo(){...}
- Cfoo() function {...}
- Dfunction foo = (){...}
86 function add(arr){
sum = 0;
for(var i = 0; i < arr.length; i++){
sum = sum + arr[i];
}
return sum;
}- Aer error
- B5
- C15
- D0
87 function foo(x){
console.log(x + " Bloc!");
}- A' Bloc!'
- B'Hello Bloc!'
- C'HelloBloc!'
- Dan error
88 function sub(n1, n2){
console.log(n1 - n2);
}- A-10
- B10
- C20
- Derror
89function isAString(x){
console.log(typeof x == 'string');
}- Astring
- Btrue
- C1
- Dfalse
90function outer (m) {
var x = 8;
var inner = function (b) {
return m * x + b;
};
return inner;
}
var foo = outer(2);
console.log(foo(4));- A6
- B14
- C20
- D16
91 var i = 1;
while(i < 0){
console.log("Hello World");
i++;
}- Ait is an infinite loop
- B1
- C0
- D2
92What is the correct format for starting a for loop in Javascript?
- Afor(var i=0; i < 100; i++){...}
- Bfor(var i=0, i < 100, i++){...}
- Cfor(var i=0, i < array.length, i++){...}
- Dfor(var array; i < array.length; i++){...}
93What will this line of Javascript evaluate to: '1' === 1?
- A0
- B1
- Cfalse
- Dtrue
94What will this line of Javascript evaluate to: '1' == 1?
- A0
- B1
- Cfalse
- Dtrue
95How many times will a for loop with the following code run: for(var i=0; i<10; i++){...}
- A10 times
- B9 times
- C11 times
- D8 times
96What is the correct format for an if statement in Javascript?
- Aif(foo = 10){...}
- Bwhen(foo < 10){...}
- Cunless(foo < 10){...}
- Dif(foo < 10){...}
97What built in Javascript function will pop up a box that allows the user to enter information?
- Aalert()
- Bprompt()
- Cerror
- D0
98 for(var i = 0; i < 10; i++){
if(i % 2 === 0){
console.log("Hello");
} else if(i % 3 === 0) {
console.log("World");
} else if(i % 2 === 0 && i % 3 === 0) {
console.log("Hello World");
} else {
console.log(i);
}
}
Using the code above, how many times will the exact phrase "Hello World" be printed to the console?- A3 times
- B6 times
- C0 times
- D2 times
99var x = 'outside';
function logToConsole() {
console.log(x);
var x = 'inside';
}
logToConsole();
What will the code above output?- A'inside'
- Bnull
- C'outside'
- Dundefined
100Which of these commands would output the string 'your data' to the console?
- Aconsole log 'your data'
- Bconsole.log('your data')
- Cconsole.output(yourData)
- Dconsole = 'your data'
101Which of these correctly creates a new variable and assigns it a value of 'Monday'?
- Avar('today', 'Monday');
- Bvar today = 'Monday';
- Cvariable today = 'Monday';
- Dtoday = 'Monday';
102What would you use to find out how many characters are in the string 'Favorite Movie'?
- A'Favorite Movie'.size()
- BString('Favorite Movie').length
- C'Favorite Movie'.length
- Dcount('Favorite Movie')
103Which one of the following expressions will evaluate to true?
- A'Great Wall of China' = 'Great Wall of China'
- B'Great Wall of China' == 'great wall of china'
- C'Great Wall of China' != 'great wall of china'
- D'Great Wall of China' !!= 'great wall of china'
104What would the following code output?
console.log('There will be ' + (42/7) + ' more weeks of winter.');- A'There will be (42/7) more weeks of winter.'
- B'There will be 6 more weeks of winter.'
- C'There will be (6) more weeks of winter.'
- DIt would throw an Uncaught SyntaxError.
105Which of these is not a valid variable name in JavaScript?
- AfavoriteFood
- Bfavorite_food
- C$favoriteFood
- Dfavorite-food
106Given the string 'Hello there!', what is the index of the letter t?
- A1
- B6
- C7
- Dundefined
107What method would you use to get a specific character of a string based on its position?
- Aindex()
- BcharAt()
- Ccharacter()
- Dlength()
108Which of these is an example of correctly including a JavaScript file in your HTML?
- A<script src="app.js"></script>
- B<javascript src="app.js"></javascript>
- C<link rel="script" href="app.js">
- D<include src="app.js"></include>
Informações
- Descrição
- Quiz sobre JavaScript, criado por Ryan Souva em 27-09-2017.
- Autor
- Ryan Souva
- Idioma
- English
- Visualizações
- 0
- Etiquetas
- Avaliação
- Ainda sem avaliações Avalie este quiz