Variables and Assignments - AP Computer Science Principles
Card 1 of 30
What keyword is used to declare a variable in JavaScript?
What keyword is used to declare a variable in JavaScript?
Tap to reveal answer
var, let, or const. JavaScript variable declaration keywords.
var, let, or const. JavaScript variable declaration keywords.
← Didn't Know|Knew It →
What is the result of the expression '10 - 2 * 5'?
What is the result of the expression '10 - 2 * 5'?
Tap to reveal answer
- Order of operations: $10 - (2 × 5) = 0$.
- Order of operations: $10 - (2 × 5) = 0$.
← Didn't Know|Knew It →
What is a variable in programming?
What is a variable in programming?
Tap to reveal answer
A named storage location for data. Variables store values that can change during program execution.
A named storage location for data. Variables store values that can change during program execution.
← Didn't Know|Knew It →
Identify the error: int x = '3';
Identify the error: int x = '3';
Tap to reveal answer
Incorrect type; use int x = 3;. Single quotes denote characters, not integers.
Incorrect type; use int x = 3;. Single quotes denote characters, not integers.
← Didn't Know|Knew It →
What symbol is used for assignment in most programming languages?
What symbol is used for assignment in most programming languages?
Tap to reveal answer
The equals sign (=). Assignment operator stores values in variables.
The equals sign (=). Assignment operator stores values in variables.
← Didn't Know|Knew It →
Identify the error: double y = 5.5.5;
Identify the error: double y = 5.5.5;
Tap to reveal answer
Syntax error; use double y = 5.5;. Double decimal point makes number invalid.
Syntax error; use double y = 5.5;. Double decimal point makes number invalid.
← Didn't Know|Knew It →
What is the result of 'x = 10 % 3;'?
What is the result of 'x = 10 % 3;'?
Tap to reveal answer
- Modulus returns remainder: $10 ÷ 3 = 3$ remainder $1$.
- Modulus returns remainder: $10 ÷ 3 = 3$ remainder $1$.
← Didn't Know|Knew It →
What does 'String name = "John";' do?
What does 'String name = "John";' do?
Tap to reveal answer
Assigns "John" to the variable name. String variable declaration and initialization.
Assigns "John" to the variable name. String variable declaration and initialization.
← Didn't Know|Knew It →
Find the value of y after: int y = 7; y -= 2;
Find the value of y after: int y = 7; y -= 2;
Tap to reveal answer
- Subtraction assignment: $7 - 2 = 5$.
- Subtraction assignment: $7 - 2 = 5$.
← Didn't Know|Knew It →
What type of error occurs when dividing by zero?
What type of error occurs when dividing by zero?
Tap to reveal answer
Arithmetic error. Division by zero is mathematically undefined.
Arithmetic error. Division by zero is mathematically undefined.
← Didn't Know|Knew It →
What is the scope of a variable declared inside a function?
What is the scope of a variable declared inside a function?
Tap to reveal answer
Local to that function. Function variables exist only within that function.
Local to that function. Function variables exist only within that function.
← Didn't Know|Knew It →
What is a constant in programming?
What is a constant in programming?
Tap to reveal answer
A variable with a fixed value. Constants cannot be modified after initialization.
A variable with a fixed value. Constants cannot be modified after initialization.
← Didn't Know|Knew It →
What is the difference between 'int' and 'double'?
What is the difference between 'int' and 'double'?
Tap to reveal answer
'int' is for integers; 'double' is for decimals. Different data types for whole vs decimal numbers.
'int' is for integers; 'double' is for decimals. Different data types for whole vs decimal numbers.
← Didn't Know|Knew It →
What is the output type of 'x / y' if x and y are int?
What is the output type of 'x / y' if x and y are int?
Tap to reveal answer
int. Integer division truncates decimal portion.
int. Integer division truncates decimal portion.
← Didn't Know|Knew It →
Which statement correctly assigns a value to a variable?
Which statement correctly assigns a value to a variable?
Tap to reveal answer
x = 5;. Proper assignment syntax with equals operator.
x = 5;. Proper assignment syntax with equals operator.
← Didn't Know|Knew It →
What does 'x -= 5;' do to x?
What does 'x -= 5;' do to x?
Tap to reveal answer
Decreases x by 5. Compound subtraction assignment operator.
Decreases x by 5. Compound subtraction assignment operator.
← Didn't Know|Knew It →
What is the outcome of '3.0 / 2' in programming?
What is the outcome of '3.0 / 2' in programming?
Tap to reveal answer
1.5. Double division produces decimal result.
1.5. Double division produces decimal result.
← Didn't Know|Knew It →
Which data type would you use for a list of values?
Which data type would you use for a list of values?
Tap to reveal answer
Array or List. Data structures for multiple related values.
Array or List. Data structures for multiple related values.
← Didn't Know|Knew It →
Identify the error: int x = '3';
Identify the error: int x = '3';
Tap to reveal answer
Incorrect type; use int x = 3;. Single quotes denote characters, not integers.
Incorrect type; use int x = 3;. Single quotes denote characters, not integers.
← Didn't Know|Knew It →
Find the value of y after: int y = 7; y -= 2;
Find the value of y after: int y = 7; y -= 2;
Tap to reveal answer
- Subtraction assignment: $7 - 2 = 5$.
- Subtraction assignment: $7 - 2 = 5$.
← Didn't Know|Knew It →
What is concatenation in programming?
What is concatenation in programming?
Tap to reveal answer
Joining two strings together. String concatenation combines text values.
Joining two strings together. String concatenation combines text values.
← Didn't Know|Knew It →
Which data type would you use for a true/false value?
Which data type would you use for a true/false value?
Tap to reveal answer
Boolean. Boolean stores only true or false values.
Boolean. Boolean stores only true or false values.
← Didn't Know|Knew It →
What is the outcome of '3.0 / 2' in programming?
What is the outcome of '3.0 / 2' in programming?
Tap to reveal answer
1.5. Double division produces decimal result.
1.5. Double division produces decimal result.
← Didn't Know|Knew It →
Which statement defines a variable in Python?
Which statement defines a variable in Python?
Tap to reveal answer
x = 10. Python uses simple assignment without type keywords.
x = 10. Python uses simple assignment without type keywords.
← Didn't Know|Knew It →
Which data type would you use for a list of values?
Which data type would you use for a list of values?
Tap to reveal answer
Array or List. Data structures for multiple related values.
Array or List. Data structures for multiple related values.
← Didn't Know|Knew It →
What happens if you exceed the range of an int variable?
What happens if you exceed the range of an int variable?
Tap to reveal answer
Overflow occurs. Values wrap around when exceeding maximum range.
Overflow occurs. Values wrap around when exceeding maximum range.
← Didn't Know|Knew It →
What is the result of the expression '10 - 2 * 5'?
What is the result of the expression '10 - 2 * 5'?
Tap to reveal answer
- Order of operations: $10 - (2 × 5) = 0$.
- Order of operations: $10 - (2 × 5) = 0$.
← Didn't Know|Knew It →
What is the purpose of a variable declaration?
What is the purpose of a variable declaration?
Tap to reveal answer
To specify a variable's type and name. Establishes variable name and data type.
To specify a variable's type and name. Establishes variable name and data type.
← Didn't Know|Knew It →
Find the value of x after: int x = 5; x += 3;
Find the value of x after: int x = 5; x += 3;
Tap to reveal answer
- Addition assignment operator: $5 + 3 = 8$.
- Addition assignment operator: $5 + 3 = 8$.
← Didn't Know|Knew It →
What is the scope of a variable declared inside a function?
What is the scope of a variable declared inside a function?
Tap to reveal answer
Local to that function. Function variables exist only within that function.
Local to that function. Function variables exist only within that function.
← Didn't Know|Knew It →