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 a core capability of JavaScript?

  • Language basics
  • Web page interaction
  • Web applications
  • All of the above (correct)

What is the purpose of client-side scripting with JavaScript?

  • To rely on server-side scripts
  • To align with Java's popularity
  • To improve web page responsiveness (correct)
  • To cause slow response times

Which of the following is the best practice for including JavaScript in an HTML document?

  • In the `<head>` section
  • Inside the `<body>` section
  • At the end of the `<body>` section (correct)
  • Before the `<html>` tag

What is a benefit of using external JavaScript files?

<p>Keeps HTML clean and separates content from behavior (A)</p>
Signup and view all the answers

Which JavaScript method is used to display content in the browser's JavaScript console?

<p>console.log() (A)</p>
Signup and view all the answers

What are JavaScript statements composed of?

<p>All of the above (D)</p>
Signup and view all the answers

What does JavaScript whitespace refer to?

<p>Extra spaces, tabs, and line breaks (A)</p>
Signup and view all the answers

What are the two types of values recognized by JavaScript?

<p>Fixed and variable values (B)</p>
Signup and view all the answers

Which keyword is used to created variables in JavaScript?

<p>All of the above (D)</p>
Signup and view all the answers

What is the purpose of a function in JavaScript?

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

JavaScript is exclusively used for server-side scripting.

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

In JavaScript, all statements must end with a semicolon.

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

JavaScript ignores whitespace like extra spaces and tabs.

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

A JavaScript expression always performs an action.

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

In JavaScript, var is the only way to declare a variable.

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

Variables declared with const cannot be reassigned.

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

A JavaScript function is not executed until it is called.

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

JavaScript functions can only contain letters in their name.

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

In JavaScript, function hoisting means you must define the function before calling it.

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

Local scope refers to variables accessible throughout the entire script.

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

What is the primary purpose of an object in JavaScript?

<p>To store multiple pieces of related data in a structured format. (C)</p>
Signup and view all the answers

Which of the following is an example of an object's attribute (property)?

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

What is the term for the actions that an object can perform?

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

In JavaScript, how can you access the value of an object's property?

<p>Using either dot notation or bracket notation. (D)</p>
Signup and view all the answers

What does it mean for objects in JavaScript to be 'dynamic'?

<p>You can add, modify, and remove properties at any time. (C)</p>
Signup and view all the answers

Which of the following is NOT a built-in JavaScript object?

<p>Car (D)</p>
Signup and view all the answers

Which built-in JavaScript object should be used to work with dates and times?

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

How are items stored in an array?

<p>Using indexed elements that are numbered starting at zero. (C)</p>
Signup and view all the answers

Which of the following object methods returns the month as an index number?

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

A variable in JavaScript holds a:

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

An object in JavaScript is simply a container for grouping different pieces of related data together.

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

Attributes, also known as behaviors, define the characteristics of an object.

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

In JavaScript, you can only access object properties using dot notation.

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

JavaScript objects are static, meaning you cannot add or remove properties after the object is created.

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

The Math object is a built-in JavaScript object that has a constructor method.

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

You should use the new keyword with String, Number, or Boolean objects in JavaScript.

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

All built-in JavaScript objects inherit from Object.prototype.

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

A JavaScript array can only store values of the same data type.

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

Arrays in JavaScript are indexed starting from 1.

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

The JavaScript getDate() method returns the weekday as an index number (0-6).

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

What is the primary purpose of control structures in JavaScript?

<p>To determine the execution flow of a program (A)</p>
Signup and view all the answers

What does the if statement do in JavaScript?

<p>It evaluates a condition and executes code if the condition is true. (A)</p>
Signup and view all the answers

What keyword is used to provide an alternative execution path when the condition in an if statement is false?

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

Which statement is used to perform different actions based on different conditions?

<p><code>switch</code> (D)</p>
Signup and view all the answers

What happens when JavaScript reaches a break keyword inside a switch block?

<p>It exits the <code>switch</code> block. (C)</p>
Signup and view all the answers

What is a loop in JavaScript?

<p>A structure that executes code repeatedly while a condition is met. (B)</p>
Signup and view all the answers

Which of the following is a component of a for loop?

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

What is the purpose of the while loop?

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

What is the main difference between a while loop and a do...while loop?

<p>A <code>do...while</code> loop always executes at least once. (B)</p>
Signup and view all the answers

What does the continue keyword do in a loop?

<p>It skips the current iteration and continues with the next one. (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 the condition.

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

The else keyword provides an alternative execution path when the if condition is false.

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

A switch statement can only test for true or false conditions.

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

In a switch statement, it is always mandatory to have a default case.

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

The break keyword in a switch statement prevents the execution of subsequent cases.

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

A for loop contains an initializer, a condition, and a modifier.

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

A while loop checks the test condition after executing the statements inside the loop.

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

A do...while loop always executes its code block at least once.

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

The continue keyword completely terminates a loop.

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

What is the top-level object in the DOM hierarchy?

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

Which property of the window.screen object provides the total width of the screen in pixels?

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

Which property of the window.screen object gives the bit value indicating the color range?

<p>colorDepth (D)</p>
Signup and view all the answers

Which method displays a simple alert box with an 'OK' button?

<p>window.alert() (C)</p>
Signup and view all the answers

Which method displays a dialog box with an input field where a user can enter text?

<p>window.prompt() (D)</p>
Signup and view all the answers

Which property of the document object can be used to get or set the title of the current document?

<p>document.title (C)</p>
Signup and view all the answers

Which property provides the full URL of the current document?

<p>document.URL (B)</p>
Signup and view all the answers

To return the number of forms in a document, you can use:

<p>document.forms.length (A)</p>
Signup and view all the answers

Which method is used to access a single element by its ID?

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

What does the load event fire?

<p>When the page has fully loaded (C)</p>
Signup and view all the answers

The DOM is not essential for creating interactive web applications.

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

JavaScript can only remove existing HTML elements and attributes; it cannot add new ones.

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

The top-level DOM window object has a 'screen' child object that provides properties describing the user's monitor resolution.

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

Window.screen.colorDepth represents colors in a hexadecimal format.

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

The top-level DOM window object provides exactly five methods for displaying dialog messages to the user.

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

The document object is a child of the 'window' object.

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

document.title only retrieves the title, it cannot be used to set it.

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

To get the number of images in a document, you would use document.images.amount.

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

The getElementsByID() method retrieves all elements with a given ID.

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

When using document.write(), the written content is appended after all existing HTML content.

<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.

Inline JavaScript

JavaScript code can be written directly in an HTML document between <script> tags.

External JavaScript

JavaScript code can be written in external .js files and linked to HTML using the <script> tag with the src attribute.

Ways to display output

Dynamically write content into an HTML element; display output using a pop-up alert; display content in the browser's JavaScript console.

Signup and view all the flashcards

Statements

Instructions that JavaScript engine executes.

Signup and view all the flashcards

Keywords

Words with special significance in the JavaScript language.

Signup and view all the flashcards

Operators

Special characters that perform operations.

Signup and view all the flashcards

Variables

Data containers for temporal values.

Signup and view all the flashcards

Functions

A block of code designed to perform a task that returns a final single value.

Signup and view all the flashcards

Scope

Determines what is the reach of a variable in a script.

Signup and view all the flashcards

ECMAScript

Standardized scripting language by Ecma International.

Signup and view all the flashcards

Language Basics

Syntax, keywords, and operators of the JavaScript language.

Signup and view all the flashcards

Web Page Interaction

Manipulating the DOM for dynamic content.

Signup and view all the flashcards

Web Applications

Creating responsive web apps and handling JSON data.

Signup and view all the flashcards

Values

Text strings, numbers, boolean true or false, undefined and null.

Signup and view all the flashcards

Expressions

Units of code that produce a single value.

Signup and view all the flashcards

Whitespace

Ignoring extra spaces, tabs, and line breaks to improve readability

Signup and view all the flashcards

Expression vs Statement

Produces a value used in calculations or function returns.

Signup and view all the flashcards

JavaScript Syntax

Describes the rules that govern the JavaScript language

Signup and view all the flashcards

JavaScript Object

A way to store multiple pieces of related data in a structured format, like a container grouping different information together.

Signup and view all the flashcards

Attributes (Properties)

Characteristics of an object, such as color, brand, or model.

Signup and view all the flashcards

Behaviors (Methods)

Actions that an object can perform, like starting, stopping, or accelerating.

Signup and view all the flashcards

Dot Notation

Using objectName.propertyName to access a property's value.

Signup and view all the flashcards

Bracket Notation

Using objectName['propertyName'] to access property values.

Signup and view all the flashcards

Dynamic Objects

Objects in JavaScript are dynamic, allowing properties to be added, modified, and removed at any time.

Signup and view all the flashcards

JavaScript Array

Built-in object that stores multiple values in a single variable.

Signup and view all the flashcards

Date object

The JavaScript Date object represents date, time, and timezone information.

Signup and view all the flashcards

Loop

A programming construct that repeats a set of instructions multiple times.

Signup and view all the flashcards

getFullYear()

Year as four digits (yyyy).

Signup and view all the flashcards

getMonth()

Month as index number (0-11).

Signup and view all the flashcards

getDate()

Day as number (1-31).

Signup and view all the flashcards

getDay()

Weekday as index number (0-6).

Signup and view all the flashcards

getHours()

Hour as number (0-23).

Signup and view all the flashcards

getMinutes()

Minute as number (0-59).

Signup and view all the flashcards

getSeconds()

Second as number (0-59)

Signup and view all the flashcards

getMilliseconds()

Millisecond as number (0-999)

Signup and view all the flashcards

Control Structures

Control structures manage the execution flow, enabling conditional execution and looping in programs.

Signup and view all the flashcards

Branch If Statement

The 'if' statement executes a code block only if a specified condition evaluates to true.

Signup and view all the flashcards

If Else Statement

Extends 'if' by adding an alternative execution path when the condition is false.

Signup and view all the flashcards

Switch Statement

A control statement that selects one of several code blocks to execute based on the value of a variable.

Signup and view all the flashcards

While Loop

Repeats a block of code as long as a condition remains true.

Signup and view all the flashcards

Do While Loop

Executes a block once, then repeats as long as a condition is true.

Signup and view all the flashcards

Break Statement

Exits a loop prematurely based on a specific condition.

Signup and view all the flashcards

Continue Statement

Skips the current iteration and continues with the next in a loop.

Signup and view all the flashcards

For Loop

A structure that contains a test condition and statements to execute repeatedly while a condition is met.

Signup and view all the flashcards

Initializer

Statement that sets an initial value of a counter variable.

Signup and view all the flashcards

Extending If with Else

Adds an alternative execution path when the initial 'if' condition is false.

Signup and view all the flashcards

Multiple Branch Alternatives

Multiple conditional tests are performed sequentially until one evaluates to true.

Signup and view all the flashcards

Loop Modifier

A statement that updates a value in the test condition within a for loop.

Signup and view all the flashcards

Switch Expression

The condition expression is evaluated once

Signup and view all the flashcards

Loop Iteration

Each cycle of checking the condition and executing a statement.

Signup and view all the flashcards

Pre-Test Loops

Loops that evaluate the condition before executing statements.

Signup and view all the flashcards

Document Object Model (DOM)

A hierarchical structure of components that represents a web page, with the window object at the top.

Signup and view all the flashcards

Screen Child Object

A DOM object that contains describes the monitor resolution in pixels.

Signup and view all the flashcards

Window.screen.width

Total screen width in pixels.

Signup and view all the flashcards

Window.screen.height

Total screen height in pixels.

Signup and view all the flashcards

Color Depth

Represents the number of colors a screen can display; measured in bits (e.g., 8-bit, 16-bit, 24-bit, 32-bit).

Signup and view all the flashcards

The window object

Top level DOM object which provides three methods to display dialog messages to the user.

Signup and view all the flashcards

Alert Dialog

Displays a simple alert box in the browser, showing a message and an 'OK' button using window.alert(message).

Signup and view all the flashcards

Confirmation Dialog

Displays a confirmation box with 'OK' and 'Cancel' buttons, returning true if 'OK' is clicked and false if 'Cancel' is clicked using window.confirm(message).

Signup and view all the flashcards

Prompt Dialog

Displays a prompt box with a text input field and 'OK' and 'Cancel' buttons, returning the input value if 'OK' is clicked using window.prompt(message, defaultValue).

Signup and view all the flashcards

Arrays of Child Objects

Objects that store their elements in an array, corresponding to elements in the HTML document.

Signup and view all the flashcards

DOM Importance:

Enables dynamic changes to a webpage without reloading

Signup and view all the flashcards

Screen Object

The element that provides properties describing the user's monitor resolution (in pixels)

Signup and view all the flashcards

Window.screen.availWidth

Usable screen width, excluding system UI elements.

Signup and view all the flashcards

Window.screen.availHeight

Usable screen height, excluding system UI elements.

Signup and view all the flashcards

document.domain

A property of the Document object that returns the domain name of the document.

Signup and view all the flashcards

document.URL

A property of the Document object that returns the full URL of the current document.

Signup and view all the flashcards

getElementByID()

Change single element, retrieves a single element by its id

Signup and view all the flashcards

innerText property

Returns only the content between its opening and closing tags.

Signup and view all the flashcards

Click event

Fired when the user clicks a mouse button

Signup and view all the flashcards

.checked Property

The property of a radio button of type boolean, which specify which in the group have been selected.

Signup and view all the flashcards

Study Notes

Meet DOM

  • All elements available within webpage components are accessible and modifiable with JavaScript.

Inspect Properties

  • The DOM window object pertains to the browser window and can be used to gather dimensions from screen space.

Show Dialogs

  • Altering an alert message, or accepting with the "OK" prompts an action, warning, or proceeds.

Extract Info

  • Dynamically updating webpages refers to modification to the content of a websites style or functionality dynamically without loading a new page.

Address Arrays

  • Objects such as forms, links, images, stylesheets, and scripts can be addressed and enumerated through the dom

Address Elements

  • These provide means of interacting with parts of a document such as with content and user experience elements.

Write Content

  • Methods of writing content include modifying existing text or inserting new elements.

Events

  • To handle events, you must understand how and why they are useful for controlling aspects and functions of the webpage.

Mouse Events

  • To react to user interaction with the cursor.

Event Values

  • Important of event objects and what context they can be used for.

Checkboxes + Radio Buttons

  • Checkboxes and radio buttons facilitate user choice selection and property values on a webpage.

Select Options

  • Selection options enumerate the state of a selected option and it interaction with user inputs.

Studying That Suits You

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

Quiz Team

Related Documents

More Like This

Client-Side Scripting Mastery
5 questions
Client-Side Scripting
4 questions

Client-Side Scripting

WellRoundedRetinalite2131 avatar
WellRoundedRetinalite2131
JavaScript Basics
40 questions
JavaScript Basics and Features
5 questions
Use Quizgecko on...
Browser
Browser