Variables & Constants in JavaScript (OCR A-Level Computer Science): Flashcards
📚Flashcards
Practise the cards
10 cards from this deck
ShowHide
Practise the cards
10 cards from this deck
What do variables store in JavaScript?
What do variables store in JavaScript?
Data values that can be used and modified
What are constants in JavaScript?
What are constants in JavaScript?
Fixed values that cannot be changed once set
Keyword to declare a variable (modern)
Keyword to declare a variable (modern)
let
Keyword to declare a constant
Keyword to declare a constant
const
Old keyword to declare variables
Old keyword to declare variables
var
Example data types in JavaScript
Example data types in JavaScript
numbers, strings, booleans
Can a const be reassigned?
Can a const be reassigned?
No, constants cannot be reassigned
Problem with var scope
Problem with var scope
Function scope can lead to unexpected results
When to use let
When to use let
For variables that change
When to use const
When to use const
For values that don't change
