What is a parameter in JavaScript?
A parameter is a variable listed in the function definition and used to accept input.
What does the return statement do in a function?
It stops the function execution and sends a value back to the caller.
What is the default return value of a function without a return statement?
undefined
What is variable scope?
The context where a variable is accessible, such as global, function, or block scope
What is the Dallas Cowboy's record?
3-7
How do you define a function with two parameters?
Draw on board
function example(param1, param2) { /* code */ }
Write a function that returns the square of a number.
Draw on Board
function square(num){
return num * num
}
Why does JavaScript return undefined for some functions?
If no return statement is provided, the function returns undefined by default.
True or False: Generally speaking, a const can be changed.
False
What is the purpose of the console.log function?
To output messages to the browser’s console, often used for debugging.
What happens if you call a function without passing a value for a parameter?
The parameter is undefined
Can a function have multiple return statements? Explain.
Yes, but only one will execute depending on the code logic.
True or False: An Argument will never override a default variable
False
What would be the difference between a block and local scope?
Block is within a for or while loop while a local scope is within a function
What is the difference between == and == in JavaScript?
== checks for equality while = assigns value
What is the difference between parameters and arguments?
Parameters are placeholders in the function definition, while arguments are actual values passed to the function.
What happens if a return statement is followed by other lines of code?
Those lines will not execute since the function exits as soon as return is encountered.
What does the following code return?
function example () {
return;
"Hello!";
}
undefined. Return terminates the function before the string.
What is a global variable, and why is it important to limit their use?
A global variable is declared outside of any function and is accessible throughout the program. Limiting their use prevents unintended overwriting and improves modularity and maintainability.
Name three JavaScript data types.
String, int, double, boolean
How can you set a default value for a parameter?
Draw on Board
By assigning a value during the function definition, e.g., function example(param = 10) { /* code */ }.
What is the difference between returning a value and modifying a variable inside a function?
function add(a, b) {
return a + b;
}
let total = 0;
function increment()
{ total++;
}
Returning a value sends it back to the function caller, while modifying a variable inside a function changes its value locally (or globally, if the variable is in global scope).
What does this code do?
if (example() == undefined)
{
console.log("Returns undefined");
}
Checks to see if the function returns undefined.
What happens with this code?
function calculate() { for (var i = 0; i < 5; i++)
{
let sum = 0;
sum += i;
}
console.log(sum);
}
calculate();
The error is: ReferenceError: sum is not defined.
What is the difference between null and undefined?
null represents an intentional absence of value, while undefined means a variable has been declared but not assigned a value.