Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Scope JS Dates JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Data Types JS Errors JS Conventions JS References

JS Versions

JS Versions

JS HTML DOM

JS HTML DOM

JS Events

JS Events

JS Projects

JS Projects

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Functions Quiz

Test Yourself

Test your knowledge of JavaScript functions.

This quiz uses the same examples you learned in the tutorial chapters.

Question 1

What is returned in the text variable?

function sayHello() {
  return "Hello World";
}

let text = sayHello();
  • A. sayHello
  • B. Hello World
  • C. undefined

Question 2

Which line calls the function?

function test() {
  return 5;
}

let x = test;
let y = test();
  • A. function test() { }
  • B. let x = test;
  • C. let y = test();

Question 3

In the function below, what are a and b?

function multiply(a, b) {
  return a * b;
}
  • A. Arguments
  • B. Parameters
  • C. Return values

Question 4

What is returned by this function call?

function add(a, b) {
  return a + b;
}

add(2, 3) * 10;
  • A. 5
  • B. 10
  • C. 50

Question 5

What value is returned if a function has no return statement?

  • A. null
  • B. false
  • C. undefined

Question 6

Which type of function can be called before it is defined?

  • A. Function declaration
  • B. Function expression
  • C. Arrow function

Question 7

Which arrow function is correct?

  • A. const add = (a, b) => return a + b;
  • B. const add = a, b => a + b;
  • C. const add = (a, b) => a + b;

Question 8

What does this refer to inside an object method?

const person = {
  name: "John",
  getName: function() {
    return this.name;
  }
};
  • A. The function itself
  • B. The global object
  • C. The object that owns the method

Question 9

Why does this code not work as expected?

const person = {
  name: "John",
  greet: () => this.name
};
  • A. Arrow functions cannot return values
  • B. Arrow functions do not have their own this
  • C. The object syntax is wrong

Question 10

What is an IIFE used for?

  • A. To delay code execution
  • B. To create a private scope
  • C. To repeat code automatically

Answers


Question 1

Answer: B.

Explanation: The function returns the string "Hello World".

Question 2

Answer: C.

Explanation: Parentheses () execute the function.

Question 3

Answer: B.

Explanation: Parameters are the names listed in the function definition.

Question 4

Answer: C.

Explanation: The function returns 5, then it is multiplied by 10.

Question 5

Answer: C.

Explanation: Functions without return return undefined.

Question 6

Answer: A.

Explanation: Function declarations are hoisted.

Question 7

Answer: C.

Explanation: Arrow functions return expressions without return when written on one line.

Question 8

Answer: C.

Explanation: In a method, this refers to the owner object.

Answer: C.

Explanation: In a method, this refers to the owner object.

Question 9

Answer: B.

Explanation: Arrow functions inherit this from their surrounding scope.

Question 10

Answer: B.

Explanation: IIFEs were commonly used to avoid global variables.


Quiz Result

If you answered most questions correctly, you have a solid understanding of JavaScript functions.

If not, revisit the chapters and try again.

Back to JavaScript Functions.


Note

Understanding functions is essential for mastering JavaScript.

Practice writing your own functions to improve faster.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->