Declaring and Redeclaring Variables in JavaScript

CourtlyOrangutan4631 avatar
CourtlyOrangutan4631
·

Start Quiz

Study Flashcards

10 Questions

What is the correct syntax for an if statement in JavaScript?

if (condition) { code }

When does the else block of an if...else statement execute in JavaScript?

When the if condition is false

What is the purpose of using else if in JavaScript conditional statements?

To execute another code block if the main condition is true

Which JavaScript statement should be used when selecting among multiple blocks of code to be executed?

switch statement

What is the purpose of a for loop in JavaScript?

To run a block of code based on a specified condition

What is hoisting in JavaScript?

A behavior where variable and function declarations are moved to the top of their containing scope during compilation

What does hoisting allow in JavaScript?

Use of variables and functions before they are declared

Which keyword was introduced in ES6 to declare variables with block scope?

let & const

What happens if you try to access a variable declared with let before its declaration?

ReferenceError

In JavaScript, what can arrays hold as elements?

Strings, numbers, objects, functions, and other arrays

Study Notes

Declaring and Redeclaring Variables

  • JavaScript variables are declared with the var keyword.
  • Variables can be assigned values when declared or later.
  • Redeclared variables do not lose their original value.

JavaScript Operators

Arithmetic Operators

  • Used to perform arithmetic between variables and/or values.
  • Examples: +, -, *, /, etc.

Assignment Operators

  • Used to assign values to JavaScript variables.
  • Examples: =, +=, -=, *=, /=, etc.

Comparison Operators

  • Used to determine equality or difference between variables or values.
  • Examples: ==, !=, ===, !==, >, <, etc.

Logical Operators

  • Used to determine the logic between variables or values.
  • Examples: &&, ||, !

Conditional Operator

  • Used to assign a value to a variable based on a condition.
  • Syntax: variablename = condition ? value1 : value2

Linking JavaScript to a Web Document

  • JavaScript can be inserted into the head section of an HTML page using the `

Learn about declaring and redeclaring variables in JavaScript using the var keyword. Practice assigning values to variables during declaration and understand how redeclaring a variable does not make it lose its original value.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

JavaScript Promises Quiz
3 questions

JavaScript Promises Quiz

ComplementaryForesight avatar
ComplementaryForesight
JavaScript Scope
5 questions

JavaScript Scope

InfallibleRationality avatar
InfallibleRationality
JavaScript Syntax and Type Conversion Quiz
12 questions
Use Quizgecko on...
Browser
Browser