Single Choice Question

  1. In a function, which statement is used to return a value?
    1. return
    2. break
    3. continue
    4. var
  2. About function, which statement is NOT correct
    1. Function always returns value
    2. Function is a value or object
    3. Function has no block scope
    4. Function name is optional
  3. The variable defined in the function is
    1. Local variable
    2. Global variable
    3. Parameter
    4. Outer variable
  4. About the var keyword, which statement is correct?
    1. 'var' is a keyword
    2. 'var' variables has no block scope
    3. 'var' variables tolerates redeclaration
    4. 'var' variables can be declared below their use
  5. What is the difference between var and let
    1. var is global, let is local
    2. var is block scope, let is function scope
    3. var is hoisted, let is not
    4. var is redeclarable, let is not
  6. What is the difference between function and arrow function?
    1. Function is a value, arrow function is a function
    2. Function is a class, arrow function is a function
    3. Function is a class, arrow function is a value
    4. Function is a value, arrow function is a class
  7. Result of the code: "let sum = new Function('a', 'b', 'return a + b');alert(sum(1, 2));" is
    1. 3
    2. NaN
    3. 1
    4. undefined
  8. Which of the following is the result of the code when user input 10:
                    
                        let age = prompt("What is your age?", 18);
                        let welcome = (age < 18) ?
                          () => alert('Hello') :
                          () => alert("Greetings!");
                        welcome();
                    
                
    1. Hello
    2. Greetings!
    3. undefined
    4. NaN
  9. What is the result of the code:
                    
                        function sum(a, b) {
                          return a + b;
                        }
                        alert(sum(1, 2) + sum(4, 5));
                    
                
    1. 12
    2. NaN
    3. 9
    4. 3
  10. What is the result of the code:
                    
                        let userName = 'John';
                        function showMessage() {
                            let userName = "Bob";
                            alert(userName);
                        }
                        showMessage();
                        alert(userName);
                    
                
    1. Bob John
    2. Bob Bob
    3. John John
    4. Error
  11. What is the result of the code if the use entered '3':
                    
                        let num = prompt("Please enter a number");
                        alert(`${num + 3}`);
                    
                
    1. 3
    2. 6
    3. 3+3
    4. 33

True or False Question

  1. Arrow functions do not have 'this' object.
  2. Local variable is not accessible outside the function.
  3. Function is a variable.
  4. Function is a class.
  5. Function is an object in JavaScript.
  6. A parameter is the variable listed inside the parentheses in the function declaration

Definition of Term

  1. IIFE
  2. Parameter
  3. Arrow function
  4. Function
  5. This
  6. Closure
  7. Callback function

Short Answer

  1. What are the ways of defining a function?
  2. What are the benefits of using a function?
  3. How many types of variables which has different scopes?
  4. Try to compare var with let.

Programming

  1. Write a function to check if a number is a prime number.
  2. Write a function to sum up all the integral numbers in a scope.
  3. Write a functions to determine that if three values can form a triangle.
  4. Write a function to calculate the area of a shape (includes square, triangle and rectangle).
  5. Write a function to calculate the factorial of a number.
  6. Write a function to calculate a quadratic equation: ax^2+bx+c=0
  7. Write a function to find the nth Fibonacci number.
  8. Write a function to find the nth prime number.