Questions and Answers
What is the JavaScript code to alert the remainder when 15 is divided by 9?
alert(15 % 9);
What assignment operator will result in x being 15 if x = 10 and y = 5?
x += y;
What assignment operator will result in x being 50 if x = 10 and y = 5?
x *= y;
What is the data type of the variable 'length' in the following code? let length = 16; // Number
Signup and view all the answers
What event makes an element turn red when someone moves the mouse over it?
Signup and view all the answers
How do you escape characters to alert 'We are Vikings'?
Signup and view all the answers
What method would you use to convert text into uppercase?
Signup and view all the answers
What JavaScript method is used to replace 'Hello' with 'Welcome' in a string?
Signup and view all the answers
What does ESLint help with?
Signup and view all the answers
What does Prettier do?
Signup and view all the answers
What symbol is used for a single-line comment in JavaScript?
Signup and view all the answers
Where do you want to place a script tag in an HTML document?
Signup and view all the answers
What does it mean when we say JavaScript is an object-oriented language?
Signup and view all the answers
What happens to the website when you write code in the browser console?
Signup and view all the answers
What is the natural environment for JavaScript?
Signup and view all the answers
What is ECMAScript?
Signup and view all the answers
What is default behavior in JavaScript?
Signup and view all the answers
What does the 'async' keyword do?
Signup and view all the answers
What does the 'defer' keyword do?
Signup and view all the answers
How do you load modules in JavaScript?
Signup and view all the answers
When does the browser execute JavaScript?
Signup and view all the answers
What are methods in JavaScript?
Signup and view all the answers
What is an object in JavaScript?
Signup and view all the answers
What are properties in JavaScript?
Signup and view all the answers
What does 'this' refer to in JavaScript?
Signup and view all the answers
What is a constant in JavaScript?
Signup and view all the answers
What does console.log do?
Signup and view all the answers
How do you access object properties?
Signup and view all the answers
What does bracket notation allow?
Signup and view all the answers
What is a parameter in JavaScript?
Signup and view all the answers
What is a class in JavaScript?
Signup and view all the answers
What is a class declaration in JavaScript?
Signup and view all the answers
What is a class expression in JavaScript?
Signup and view all the answers
What does the constructor method do?
Signup and view all the answers
What is the difference between class and object constructor functions?
Signup and view all the answers
How do you get the current date and convert it into a string?
Signup and view all the answers
How do you find the age of an object in JavaScript?
Signup and view all the answers
How do you access the property named in a variable in JavaScript?
Signup and view all the answers
What is the code in the second line of an object called?
Signup and view all the answers
Why is it best practice to place objects inside constants?
Signup and view all the answers
Which object property names are not valid?
Signup and view all the answers
How do you access an object in JavaScript?
Signup and view all the answers
Can an object created from a class be given the same name as the class?
Signup and view all the answers
How do you define an object in JavaScript?
Signup and view all the answers
Where do you find official documentation for built-in objects?
Signup and view all the answers
How do you create a new object from a class?
Signup and view all the answers
What is the established convention for formatting objects?
Signup and view all the answers
What is the difference between a function and a method?
Signup and view all the answers
Can you use arrow functions to create object methods?
Signup and view all the answers
When creating a class, are prototype methods added inside the constructor method?
Signup and view all the answers
What is a template literal in JavaScript?
Signup and view all the answers
How to show the value of everydayPack.name?
Signup and view all the answers
How do you declare a JavaScript expression inside a template literal?
Signup and view all the answers
How do you select the main element using query selector?
Signup and view all the answers
How to select the last name in the list using query selector?
Signup and view all the answers
How do you change all list items in the list to red?
Signup and view all the answers
How do you find the class name of an h1 element?
Signup and view all the answers
How do you change the class name of an h1 element?
Signup and view all the answers
How do you add a new class using query selector?
Signup and view all the answers
How do you remove a class using query selector?
Signup and view all the answers
How do you replace a class using query selector?
Signup and view all the answers
When should you use className?
Signup and view all the answers
How to select the style of the .site-title?
Signup and view all the answers
How to select the color of the .site-title?
Signup and view all the answers
How to change the color of the .site-title?
Signup and view all the answers
How to get the property name of a style in .site-title?
Signup and view all the answers
How to create a new element and append it to your document?
Signup and view all the answers
How to create a new element for a nav menu?
Signup and view all the answers
What method(s) would you use to check if an element has a specific ID?
Signup and view all the answers
What is the difference between element.className and element.classList?
Signup and view all the answers
What does the HTML markup of a new img element look like after the given script executes?
Signup and view all the answers
What is the value of const target after this code executes?
Signup and view all the answers
What is the value after executing const target = document.getElementsByClassName('.note');?
Signup and view all the answers
What kind of selectors do querySelector and querySelectorAll use?
Signup and view all the answers
What happens if you run this code: target.style.font-family = 'sans-serif';?
Signup and view all the answers
What does the element.classList.toggle() method do?
Signup and view all the answers
Where does the new element appear when using document.createElement?
Signup and view all the answers
What is the 'DOM'?
Signup and view all the answers
How do you add an element created using createElement() to the DOM?
Signup and view all the answers
What is a variable in JavaScript?
Signup and view all the answers
In the expression var name = piggy, what is 'piggy'?
Signup and view all the answers
What does 'let' do in JavaScript?
Signup and view all the answers
When should you use 'const'?
Signup and view all the answers
How to find the type of a variable in JavaScript?
Signup and view all the answers
What is the difference between assignment and comparison operators?
Signup and view all the answers
What is absolute equivalence in JavaScript?
Signup and view all the answers
How do you express 'a' to the power of 'b'?
Signup and view all the answers
How do you increment a number before or after output?
Signup and view all the answers
What does a single equals symbol in JavaScript indicate?
Signup and view all the answers
What happens if you use a named variable without first declaring it?
Signup and view all the answers
What is the value of defaultColor after executing provided code?
Signup and view all the answers
How do you capture the result of a math equation like 42 * 38 in JavaScript?
Signup and view all the answers
How do you create a function to display 'Hello' in the inner HTML of an element with the ID 'demo'?
Signup and view all the answers
In what scenario should you use var instead of let?
Signup and view all the answers
Which statement is true?
Signup and view all the answers
Study Notes
JavaScript Basics
-
alert(15%9);
alerts the remainder when 15 is divided by 9. -
x += y;
is an assignment operator resulting inx
being 15, equivalent tox = x + y
. -
x *= y;
assigns 50 tox
, same asx = x * y
.
Data Types and Variables
- Use comments to document:
-
let length = 16; // Number
-
let lastName = "Johnson"; // string
-
const x = { firstName: "John", lastName: "Doe" }; // object
-
-
onmouseover
triggers when the mouse hovers over an element. - Escape characters allow for double quotes in strings:
We are \"Vikings\"
.
String Methods
- Convert text to uppercase using
toUpperCase()
. - Replace substrings using:
let txt = "Hello World"; txt = txt.replace("Hello", "Welcome");
Code Quality Tools
- ESLint: detects coding errors and requires Node.js.
- Prettier: formats code cleanly and also requires Node.js.
Commenting
- Single line comment syntax:
//
- Multi-line comment syntax:
/* comment here */
.
JavaScript Execution
- Script tags are generally placed within the head for initial loading.
- JavaScript is object-oriented, modeled around objects with properties and methods.
- Browser console code affects only the current session and is lost upon refresh.
ECMAScript and Browser Behavior
- ECMAScript: specification for JavaScript's implementation in browsers.
- Default JavaScript behavior can block rendering until execution is complete (content blocking).
-
async
downloads scripts in parallel with HTML, whiledefer
ensures scripts only execute after HTML parsing completion.
Object-Oriented Programming
- To create and use classes in JavaScript, declare with
class ClassName {}
. - Constructors define properties and methods for class instances.
- Methods are functions within objects; functions are standalone.
Working With Objects
- Object properties are accessed using dot notation (e.g.,
backpack.name
) or bracket notation (e.g.,backpack["pocketNum"]
). - Constants hold values that cannot be reassigned after initialization.
- A variable created from a class cannot have the same name as the class itself to avoid conflicts.
The Document Object Model (DOM)
- DOM represents the structure of an HTML document as objects; can be manipulated using methods like
document.createElement()
. - Use
document.querySelector()
to select elements using CSS selectors. - Element manipulation involves adding, removing, or replacing classes and elements through properties like
classList
.
Creating and Modifying Elements
- To create and append new elements:
const newArticle = document.createElement("article"); main.append(newArticle);
- Use
appendChild()
orinsertAdjacentElement()
to add elements to the DOM.
Data Types and Operators
- Use
typeof
to determine variable types. - Assignment vs comparison:
=
for assignment,==
for equality check,===
for strict equality. - Increment numbers with
++a
ora++
.
Array Manipulation
- Add items to an array with
collection[collection.length] = "new item"
orbackpackContents.push("pencil", 5)
.
Best Practices
- Keep object definitions within constants to prevent unintentional alterations.
- Use
let
orconst
for variable declarations to ensure scope is maintained. - Object properties in constants can be modified but the reference itself cannot be changed.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Test your knowledge of JavaScript through interactive flashcards. Each card covers essential concepts such as operators, alerts, and comments. Perfect for students looking to strengthen their programming skills in JavaScript.