Podcast
Questions and Answers
What happens when you try to access a let variable before its declaration?
What happens when you try to access a let variable before its declaration?
- It results in a reference error. (correct)
- It returns null.
- It returns the value of the variable.
- It returns undefined.
What is a primary characteristic of a const variable compared to var and let variables?
What is a primary characteristic of a const variable compared to var and let variables?
- It can be redeclared without error.
- It can be modified after declaration.
- It must be declared globally.
- It cannot be initialized multiple times. (correct)
Which statement is true regarding the redeclaration of variables?
Which statement is true regarding the redeclaration of variables?
- A const variable can be redeclared after initialization.
- A var variable can be redeclared without errors. (correct)
- A let variable will throw an error if redeclared.
- A let variable can be redeclared multiple times.
What value does a var variable return if accessed before it is assigned any value?
What value does a var variable return if accessed before it is assigned any value?
What occurs when you attempt to reassign a const variable after its initial declaration?
What occurs when you attempt to reassign a const variable after its initial declaration?
Flashcards
var access before init
var access before init
Variables declared with 'var' can be accessed before initialization, returning 'undefined'.
var redeclaration
var redeclaration
You can redeclare a 'var' variable multiple times without errors; the last assignment prevails.
let access before decl
let access before decl
'let' variables can't be accessed before their declaration; attempting to do so results in an error.
let redeclaration
let redeclaration
Signup and view all the flashcards
const initialization
const initialization
Signup and view all the flashcards
Study Notes
Variable Declarations: var, let, and const
-
var
:- Accessible before initialization, returning
undefined
if not assigned. - Can be redeclared multiple times; the last assignment prevails.
- Accessible before initialization, returning
-
let
:- Cannot be accessed before declaration; attempting to do so throws a reference error.
- Cannot be redeclared, but can be reassigned after declaration.
-
const
:- Must be initialized when declared; otherwise, a syntax error will occur.
- Cannot be redeclared or reassigned. This is the strictest declaration type.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.