HansR on the Web - All quiz questions on JavaScript
Updated: 14-03-2018 23:42:08h
topics: javascript|web workers, level: 100
What best describes a Web Worker?
Please select exactly one correct alternative.

Answer

A Web Worker is a JavaScript that runs in the background, independently of other scripts, without affecting the performance of the page. You can continue to do whatever you want: clicking, selecting things, etc., while the web worker runs in the background.
topics: javascript, level: 100
What does
"use strict";
in your JavaScript code mean?
Please select exactly one correct alternative.

Answer

"use strict" defines that JavaScript code should be executed in "strict mode". With strict mode, you can not, for example, use undeclared variables.
topics: javascript|scope, level: 100
Which statements below are correct on scopes and variables?
Please select exactly one or more correct alternatives.

Answer

Please see the correct answer above.
topics: javascript, level: 100
What is the difference between
split()
and
splice()
?
Please select exactly one correct alternative.

Answer

split()
operates on strings and
splice()
operates on arrays.
topics: javascript|external scripts, level: 100
How does your browser handle this?
How does your browser handle an external JavaScript when neither defer nor asyn is present in
<script src="myscript.js"></script>
?
Please select exactly one correct alternative.

Answer

If neither async or defer is present: The script is fetched and executed immediately, before the browser continues parsing the page.
topics: javascript, level: 100
What is
async
used for?
What is
async
in
<script src="myscript.js" async></script>
used for?
Please select exactly one correct alternative.

Answer

async
Indicated that the script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing).
topics: javascript, level: 100
What will this code do?
Consider the following code:
<script>

 myFunction();
 
    function myFunction() {
        alert(vMyVar);
    }
 
    var vMyVar = "Hello HansR!";

</script>
What will this result into?
Please select exactly one correct alternative.

Answer

The variable has not been given a value before you used it, so the value is undefined.
topics: javascript, level: 100
What will this code do?
Consider the following code:
<script>

    vMyVar = "Hello HansR!";
 
 myFunction();
 
    function myFunction() {
        alert(vMyVar);
    }

</script>
What will this result into?
Please select exactly one correct alternative.

Answer

You correctly declared the variable and have given it a value. So it will display this value.
topics: javascript, level: 100
Which code fragment presents a correct way to walk through an array?
Please select exactly one correct alternative.

Answer

Array indices go from 0 to length - 1 in JavaScript.
topics: javascript, level: 100
What is
defer
used for?
What is
defer
in
<script src="myscript.js" defer></script>
used for?
Please select exactly one correct alternative.

Answer

defer
Indicates that the script will not run until after the page has been loaded.
topics: javascript, level: 100
How can you test whether a variable is undefined?
Please select exactly one correct alternative.

Answer

if (vMyVar === undefined) { vMessage = "vMyVar undefined"; } else { vMessage = "vMyVar defined"; }
is the correct way. Using == is not good idea there because in JavaScript, you can name a variable as undefined too.
topics: javascript|scope, level: 100
Which statements below are correct on scopes and variables?
Please select exactly one or more correct alternatives.

Answer

Please see the correct answer above.
topics: javascript|scope, level: 100
Which statements below are correct on scopes and variables?
Please select exactly one or more correct alternatives.

Answer

Please see the correct answer above.
topics: javascript|scope, level: 100
What best describes a JavaScript scope?
Please select exactly one correct alternative.

Answer

Scope is the set of variables, objects, and functions you have access to.
topics: javascript|objects, level: 100
What is prototypical inheritance?
Please select exactly one correct alternative.

Answer

Prototypical inheritance means that child scopes prototypically inherit from their parents.
topics: javascript|variables, level: 100
What is the correct method to add new items at the end of an array?
Please select exactly one correct alternative.

Answer

The push() method adds new items to the end of an array.
topics: javascript|variables, level: 100
What does the
unshift()
method do?
Please select exactly one correct alternative.

Answer

The unshift() method adds new items to the beginning of an array.
topics: javascript|expressions, level: 100
What value is valid considering the pattern
"/\d{3,4}/g"
?
Please select exactly one correct alternative.

Answer

The expression checks for number strings of 3 to 4 digits.
topics: javascript, level: 100
What will this code do?
Consider the following code:
<script>

    function myFunction() {
        vMyVar = "Hello HansR!";
    }
    
    alert(vMyVar);

</script>
What will this result into?
Please select exactly one correct alternative.

Answer

You have not defined the variable, so your browser will throw an error on it.
topics: javascript|syntax, level: 100
What are advantages of putting your JavaScript code into an external .js file?
Please select exactly one or more correct alternatives.

Answer

Placing JavaScripts in external files has some advantages:
  • It separates HTML and code.
  • It makes HTML and JavaScript easier to read and maintain.
  • Cached JavaScript files can speed up page loads.
topics: javascript,javascript|promise, level: 100
What is a JavaScript promise?
Please select exactly one correct alternative.

Answer

An AngularJS promise (or just a JavaScript promise) is a way for handling asynchronous operations.

Reading

Promise
topics: javascript|array, level: 100
Which method should you use when you want to delete an entry in a JavaScript array?
Please select exactly one correct alternative.

Answer

Please see the correct answer above.

Reading

No resources given.
topics: javascript, level: 100
How can you minimize the global namespace pollution in JavaScript?
Please select exactly one correct alternative.

Answer

Please see the correct answer above.

Reading

No resources given.
topics: javascript|output, level: 100
Which of the following statements are correct on JavaScript output functions?
Please select exactly one or more correct alternatives.

Answer

Please see the correct answer above.
When using the
console.log
function in IE, please make sure that the console has been opened first. If not, IS will give an error message.
topics: javascript, level: 100
Which of the below are correct statements on JavaScript?
Please select exactly one or more correct alternatives.

Answer

You can use the sites below to learn about this topic.

Reading

JavaScript
topics: javascript|libraries, level: 100
What is Modernizr and what is it's purpose?
Please select exactly one correct alternative.

Answer

Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user's browser.
Taking advantage of cool new web technologies is great fun, until you have to support browsers that lag behind. Modernizr makes it easy for you to write conditional JavaScript and CSS to handle each situation, whether a browser supports a feature or not.
topics: javascript, level: 100
What is the
splice()
function used for?
Please select exactly one correct alternative.

Answer

The splice() method changes the content of an array by removing existing elements and/or adding new elements, as in the example below.
var vMyArray = ["First", "Second", "Third"];
vMyArray.splice(2, 0, "New third", "New fourth");
     

The result of vMyArray will be:
First,Second,New third,New fourth,Third
     
topics: javascript|timing, level: 100
What is the difference between
setTimeout
and
setInterval
?
Please select exactly one correct alternative.

Answer

Both functions execute a given function in a given time. But setTimeout only executes this function once, while setInterval schedules a repeating execution.
topics: javascript|functions, level: 100
What is a self invoked function?
Please select exactly one correct alternative.

Answer

A self invoked function is a function that is stored within a JavaScript variable.
topics: javascript|syntax, level: 100
Which are correct examples for comments in JavaScript?
Please select exactly one or more correct alternatives.

Answer

Comments can be placed in between <!-- and --> or after // in JavaScript.
topics: javascript|syntax, level: 100
Where can you place your JavaScript in your web page?
Please select exactly one correct alternative.

Answer

Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.
topics: javascript, level: 100
Which of the below are correct statements on JavaScript?
Please select exactly one or more correct alternatives.

Answer

Please see the resources below.

Reading

JavaScript
topics: javascript|operators, level: 100
What is the difference between
==
and
===
in JavaScript expressions?
Please select exactly one correct alternative.

Answer

=== Means: equal value and equal type, == only means equal.
topics: javascript, level: 100
Which code fragment presents a correct way to walk through an array?
Please select exactly one correct alternative.

Answer

An index for a JavaScript array runs from 0 to length - 1. Hence, the correct way to walk through an array is:
(vIndex = 0; vIndex < vArray.length; ++vIndex)
.

Reading

No resources given.
topics: javascript|expressions, level: 100
What value is valid considering the pattern
"/\d{3,4}/g"
?
Please select exactly one correct alternative.

Answer

The expression checks for number strings of 3 to 4 digits.
topics: javascript, level: 100
Which statements are correct on
null
,
empty
and
undefined
in JavaScript?
Please select exactly one or more correct alternatives.

Answer

Please see the correct answer above.

Reading

No resources given.
topics: javascript|timing, level: 100
Why is it not recommended to have many setInterval / setTimeout at the same time?
Please select exactly one correct alternative.

Answer

They cost a lot of CPU time. This could make your browser slow. Ofcourse, this depends on the processing power of your machine. In general, mobile devices are slower than e.g. desktop devices. It is preferred that a single setInterval / setTimeout call manages multiple animations.
That's all folks!

Congratulations, you've made it to the end! I'll try to add more questions and topics on a regular basis.

More questions?

If you have enjoyed the quiz and you want more, you can select other tests by clicking the green buttons below.

Other resources

There are many quizzes and learning resources on the internet. Below you'll links to a selection of these. I'll add more. Quizzes from others
Learning resources
Take a look at my blog

Contact

Please contact me for feedback, suggestions and questions. hansrontheweb@live.com
Other quizzes

all topics
latest questions
html
css
javascript
jquery
bootstrap
architecture
software engineering
c#
sharepoint
xml
powershell
angular