What is a variable?
A named storage location in memory that holds a data value that can change.
What value does num hold after running: var num = 5; num = num + 2;
7
What is string concatenation?
Combining two or more text strings together using the + operator.
What is variable scope?
The region of a program where a specific variable is accessible.
What value does score hold after: var score = 0; score = score + 5; score = score * 2;?
10
Which operator is used to assign a value to a variable in JavaScript?
The equal sign (=)
What value is stored in y after: var x = 10; var y = x; x = 20;?
10
What is the result of the expression: "Code" + " " + "org"?
"Code org"
Where is a global variable declared in a program?
Outside of any function, making it accessible everywhere.
What is the value of temp after: var a = 1; var b = 2; var temp = a; a = b; b = temp;?
1 (The standard swap algorithm)
What does the keyword var do when placed before a variable name?
It declares (creates) the variable in memory
What value is stored in x after: var x = 10; var y = x; x = 20;?
20
What is the result of the expression: "5" + 5 in JavaScript?
"55"
Where is a local variable declared, and where can it be accessed?
Inside a specific function, accessible only within that function.
What is displayed if we run: var x = 4; console.log("x is " + x);?
x is 4
What value will a variable evaluate to if used before being assigned a value?
undefined
What happens to the old value stored in a variable when a new value is assigned to it?
It is overwritten and permanently lost.
What is the data type of the value stored in: var count = 42;?
Number
What happens to a local variable after its function finishes executing?
It is deleted/destroyed from memory.
What is the value of ans after: var a = "10"; var b = "20"; var ans = a + b;?
"1020"
Why should variable names be descriptive (e.g., userScore instead of x)?
It improves code readability and makes programs easier to debug.
What is the final value of b after: var a = 3; var b = 4; b = a; a = b + 1;?
3
What is the result of: var name = "Ada"; var msg = "Hello " + name;?
"Hello Ada"
If a global and local variable share the same name, which takes precedence inside the function?
The local variable.
What is the final value of total after: var total = 100; total = total - 25; total = total / 3;?
25