Variable Basics
Assignment & Values
Data Types & Strings
Variable Scope
Code Tracing
100

What is a variable?

A named storage location in memory that holds a data value that can change.

100

What value does num hold after running: var num = 5; num = num + 2;

7

100

What is string concatenation?

Combining two or more text strings together using the + operator.

100

What is variable scope?

The region of a program where a specific variable is accessible.

100

What value does score hold after: var score = 0; score = score + 5; score = score * 2;?

10

200

Which operator is used to assign a value to a variable in JavaScript?

The equal sign (=)

200

What value is stored in y after: var x = 10; var y = x; x = 20;?

10

200

What is the result of the expression: "Code" + " " + "org"?

"Code org"

200

Where is a global variable declared in a program?

Outside of any function, making it accessible everywhere.

200

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)

300

What does the keyword var do when placed before a variable name?

It declares (creates) the variable in memory

300

What value is stored in x after: var x = 10; var y = x; x = 20;?

20

300

What is the result of the expression: "5" + 5 in JavaScript?

"55"

300

Where is a local variable declared, and where can it be accessed?

Inside a specific function, accessible only within that function.

300

What is displayed if we run: var x = 4; console.log("x is " + x);?

x is 4

400

What value will a variable evaluate to if used before being assigned a value?

undefined

400

What happens to the old value stored in a variable when a new value is assigned to it?

It is overwritten and permanently lost.

400

What is the data type of the value stored in: var count = 42;?

Number

400

What happens to a local variable after its function finishes executing?

It is deleted/destroyed from memory.

400

What is the value of ans after: var a = "10"; var b = "20"; var ans = a + b;?

"1020"

500

Why should variable names be descriptive (e.g., userScore instead of x)?

It improves code readability and makes programs easier to debug.

500

What is the final value of b after: var a = 3; var b = 4; b = a; a = b + 1;?

3

500

What is the result of: var name = "Ada"; var msg = "Hello " + name;?

"Hello Ada"

500

If a global and local variable share the same name, which takes precedence inside the function?

The local variable.

500

What is the final value of total after: var total = 100; total = total - 25; total = total / 3;?

25

M
e
n
u