JavaScript Flashcards
What can JavaScript do in relation to HTML and CSS on a web page?
JavaScript can:
• Change all HTML elements on the page.
• Change all HTML attributes on the page.
• Change all CSS styles on the page.
• Remove existing HTML elements and attributes.
• Add new HTML elements and attributes.
• React to all existing HTML events on the page.
• Create new HTML events on the page.
What are the two techniques for placing JavaScript code on a web page?
- Place JavaScript code as part of an event attached to an HTML element within the body element (usually for event handling).
- Place JavaScript code between •
...
tags or •...
tags (either internally or externally).
Where can JavaScript be placed in a web page?
JavaScript can be placed internally within a web page (inside
tags in the HTML file) or externally by linking to a .js file.
Give an example of a basic JavaScript statement.
A basic JavaScript statement might be:
alert(“Hello, World!”);
This will display an alert message box with the text “Hello, World!”
What is the proper format for JavaScript statements?
JavaScript statements should be a single line of instructions followed by a semicolon ;. Multiple statements make up a JavaScript program.
What are the common data types in JavaScript?
The common data types in JavaScript are:
Number
String
Boolean
How do you declare a variable in JavaScript?
You can declare a variable using the var keyword, like this:
var height;
What are the rules for creating variable names in JavaScript?
• Variable names must begin with a letter, $, or _.
• Variable names can only contain letters, numbers, $, and _ (no spaces or special characters).
• Variable names are case-sensitive.
• Avoid using JavaScript keywords like var, alert, document, or window.
How can you write to a web page using JavaScript?
You can write to a web page using:
• alert() to display a message box.
• .innerHTML to change the content of an HTML element
• .document.write() to directly write HTML content.
What are arrays in JavaScript?
Arrays in JavaScript are collections of data. They can store multiple values in a single variable. You can access array data using its index.
How do you combine strings and other data in JavaScript?
You can combine strings and other data using the + operator. Example:
var name = “John”;
alert(“Hello “ + name);
However, the + operator behaves differently when used with numbers, so caution is needed.
How can you add comments in JavaScript?
You can add comments using:
• // for single-line comments.
• /* … */ for multi-line comments.
What are some common operations JavaScript supports?
JavaScript supports:
• Basic mathematical operations (addition, subtraction, etc.).
• Logical comparisons (like ==, !=, >, <).
What is a JavaScript function?
A function in JavaScript is a block of code designed to perform a specific task. For example, alert() is a built-in JavaScript function to display an alert box.
What is JavaScript’s role in web development?
JavaScript is a lightweight programming language used to create dynamic and interactive elements on web pages. It accesses web page content through the DOM (Document Object Model), and supports user interaction and basic math operations.