Introduction to JavaScript

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

Which of the following is the correct way to include JavaScript code directly within an HTML document?

  • <javascript> // JavaScript code </javascript>
  • <embed> // JavaScript code </embed>
  • <js> // JavaScript code </js>
  • <script> // JavaScript code </script> (correct)

Which of the following is NOT a component that a JavaScript statement may contain?

  • Paragraphs (correct)
  • Keywords
  • Values
  • Operators

Which of the following keywords is used to declare a variable in JavaScript that cannot be reassigned?

  • dynamic
  • const (correct)
  • var
  • let

What does the parseInt() function in JavaScript do?

<p>Converts a string to an integer (A)</p>
Signup and view all the answers

What is the purpose of the return statement in a JavaScript function?

<p>To stop the execution of the function and optionally return a value (B)</p>
Signup and view all the answers

JavaScript code can only be included in an HTML document directly, not from an external file.

<p>False (B)</p>
Signup and view all the answers

In JavaScript, total and Total are treated as the same variable.

<p>False (B)</p>
Signup and view all the answers

Using mixed data types in JavaScript operations always leads to predictable and desired outcomes.

<p>False (B)</p>
Signup and view all the answers

The const keyword in JavaScript allows you to reassign a new value to the declared variable after its initial assignment.

<p>False (B)</p>
Signup and view all the answers

In JavaScript, function declarations can be called before they are defined in the code due to a feature called hoisting.

<p>True (A)</p>
Signup and view all the answers

Which of the following best describes a JavaScript object?

<p>A way to store multiple pieces of related data in a structured format. (D)</p>
Signup and view all the answers

Which of the following is used to access object methods?

<p>Dot notation (C)</p>
Signup and view all the answers

What is the correct way to add a new property to an existing JavaScript object?

<p>Both A and C (A)</p>
Signup and view all the answers

Which of the following is a characteristic of JavaScript objects?

<p>They are dynamic, allowing properties to be added and removed. (D)</p>
Signup and view all the answers

Using the JavaScript Date object, which method returns the month as an index number?

<p><code>getMonth()</code> (A)</p>
Signup and view all the answers

In JavaScript, an object is used to store multiple, unrelated pieces of data.

<p>False (B)</p>
Signup and view all the answers

A car object can have attributes like color, brand, model and speed.

<p>True (A)</p>
Signup and view all the answers

In JavaScript, object property values can only be referenced using dot notation syntax.

<p>False (B)</p>
Signup and view all the answers

JavaScript objects are static, meaning you can't add new properties after the object is created.

<p>False (B)</p>
Signup and view all the answers

The JavaScript built-in Array object stores items in individual elements that are numbered starting at 1.

<p>False (B)</p>
Signup and view all the answers

Which of the following determines the execution flow of a program?

<p>Control structures (C)</p>
Signup and view all the answers

What is the purpose of the if statement in JavaScript?

<p>To execute code only when a condition is true. (C)</p>
Signup and view all the answers

In a switch statement, what happens when a break keyword is encountered?

<p>The <code>switch</code> statement exits, and the program continues with the next statement after the <code>switch</code> block. (D)</p>
Signup and view all the answers

Which part of a for loop is responsible for updating the loop counter?

<p>Modifier (C)</p>
Signup and view all the answers

What is the key difference between a while loop and a do...while loop in JavaScript?

<p>A <code>do...while</code> loop always executes at least once, while a <code>while</code> loop might not execute at all. (C)</p>
Signup and view all the answers

Control structures determine the execution flow of a program.

<p>True (A)</p>
Signup and view all the answers

The if statement executes code regardless of whether the condition is true or false.

<p>False (B)</p>
Signup and view all the answers

A switch statement can be used to perform different actions based on different conditions.

<p>True (A)</p>
Signup and view all the answers

In a switch block, omitting the break statement will prevent the next case from being executed, even if it matches.

<p>False (B)</p>
Signup and view all the answers

A do...while loop evaluates the condition before executing the statements within the loop.

<p>False (B)</p>
Signup and view all the answers

Flashcards

What is JavaScript?

A language embedded in web browsers that enables client-side scripting, improving web page responsiveness.

Including JavaScript

JavaScript can be included directly within HTML using <script> tags or via external .js files referenced in the HTML.

JavaScript Statement

A series of instructions executed by the JavaScript engine.

JavaScript Function

A named block of code designed to perform a particular task, and it returns a final single value.

Signup and view all the flashcards

Scope in JavaScript

Determines where a variable is accessible. Can be global or local.

Signup and view all the flashcards

Writing to HTML Elements

Writes dynamic content into an HTML element using its ID.

Signup and view all the flashcards

Keywords in JavaScript

Words with special significance in JavaScript.

Signup and view all the flashcards

JavaScript Variables

Values that can be changed during the execution of a script.

Signup and view all the flashcards

Global Scope

Variables declared outside a function; accessible throughout the script.

Signup and view all the flashcards

parseInt()

Converts a string to an integer in JavaScript.

Signup and view all the flashcards

What is an Object?

A way to store multiple pieces of related data in a structured format; a container for grouping information.

Signup and view all the flashcards

Object Attributes (Properties)

Characteristics of an object, like color, brand, or model.

Signup and view all the flashcards

Object Behaviors (Methods)

Actions an object can perform, such as start(), stop(), or accelerate().

Signup and view all the flashcards

Object Dot Notation

Access an object's property: objectName.propertyName

Signup and view all the flashcards

JavaScript Array

A built-in JavaScript object that stores multiple values in a single variable; uses square brackets [].

Signup and view all the flashcards

Object Bracket Notation

A way to reference object properties, using brackets and quotes: objectName['propertyName'].

Signup and view all the flashcards

Prototype Inheritance

Built-in objects inherit properties and methods from Object.prototype.

Signup and view all the flashcards

getFullYear()

Built-in Date object method that retrieves the year as a four-digit number (yyyy).

Signup and view all the flashcards

getMonth()

Built-in Date object method that retrieves the month as an index number, 0-11.

Signup and view all the flashcards

Extending Objects

Objects can be modified by adding new properties, modifying existing ones, and removing unneeded properties.

Signup and view all the flashcards

What are Control Structures?

Control structures determine the order in which statements are executed, allowing for conditional execution and looping.

Signup and view all the flashcards

What is an if statement?

The if statement executes a block of code only if a specified condition is true.

Signup and view all the flashcards

What does else do in an if statement?

Extends the if statement by providing an alternative block of code to execute if the condition is false.

Signup and view all the flashcards

What is a switch statement?

A control flow statement that allows executing different blocks of code based on the value of a variable or expression.

Signup and view all the flashcards

What is a while loop?

A loop that executes a block of code repeatedly as long as a specified condition is true.

Signup and view all the flashcards

Extending If with Else

Adds an alternative execution path when the condition is false in an if statement.

Signup and view all the flashcards

For loop

A loop structure specifies an initializer, a condition, and a modifier to control the number of iterations to exit the loop.

Signup and view all the flashcards

Do While Loop

A loop evaluates the condition after the code block is executed at least once.

Signup and view all the flashcards

Break Statement

Exits a loop prematurely when a specified condition is met.

Signup and view all the flashcards

Continue Statement

Skips the current iteration and proceeds with the next one.

Signup and view all the flashcards

Study Notes

  • Control structures determine the execution flow of a program.
  • Control structures facilitate conditional execution and looping.
  • Control structures enable decision-making and repetitive execution.
  • Control structures are essential for efficient coding and logic building.

Branch If

  • The if statement evaluates a condition.
  • The if statement executes code only if the condition is true.
  • Syntax for if statement:
if (condition) {
  // block of code to be executed if the condition is true
}
  • Example:
if (hour < 18) {
  greeting = "Good day";
}

Branch Alternatives (If/Else)

  • Extending if with else adds an alternative execution path for when the condition is false.
  • Syntax for if/else statement:
if (condition) {
  // block of code to be executed if the condition is true
} else {
  // block of code to be executed if the condition is false
}
  • Example:
if (hour < 18) {
  greeting = "Good day";
} else {
  greeting = "Good evening";
}

Branch Alternatives (Multiple Branches)

  • Multiple branches use subsequent conditional if tests at the start of each else statement block.
  • Syntax for multiple branch if/else if statement:
if (condition) {
  // block of code to be executed if the condition is true
} else if (condition) {
  // block of code to be executed if the condition is false
}
  • Example:
if (hour < 18) {
  greeting = "Good day";
} else if (hour < 24) {
  greeting = "Good evening";
}

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

JavaScript Basics and Evolution
40 questions
Javascript Basics
80 questions
Introduction to Javascript
80 questions
Use Quizgecko on...
Browser
Browser