JavaScript From Beginner To Advanced
0% completed
Previous
Next
Course
Discussions
Quiz
How do you define a function in JavaScript that calculates the sum of two numbers?
Choose all correct options
function sum(a + b) { return a + b; }
function sum(a, b) { return a + b; }
sum(a, b) => return a + b;
let sum = function(a, b) { return a + b; };
Reset Quiz
Check Answer
What is the default return value of a function in JavaScript that does not explicitly return a value?
A
null
B
0
C
undefined
D
false
Reset Quiz
Check Answer
How do you declare a function with default parameters in JavaScript?
Choose all correct options
function greet(name = "Guest") { console.log("Hello, " + name); }
function greet(name: "Guest") { console.log("Hello, " + name); }
function greet(name || "Guest") { console.log("Hello, " + name); }
let greet = function(name = "Guest") { console.log("Hello, " + name); };
Reset Quiz
Check Answer
What is output by the following arrow function in JavaScript?
let add = (a, b) => a + b; console.log(add(5, 7));
A
12
B
7
C
undefined
D
Error
Reset Quiz
Check Answer
Which statement is true about variable scope within a JavaScript function?
A
Variables declared with var inside a function are global.
B
Variables declared with let inside a function can be accessed outside the function.
C
Variables declared with var inside a function are local to the function.
D
Variables declared with const inside a function are hoisted to the global scope.
Reset Quiz
Check Answer
.....
.....
.....
Like the course? Get enrolled and start learning!
Enroll
Previous
Next