WebDesign JScript Flashcards
What is the history of JavaScript? (4)
- was invented by Brendan Eich in 1995
- became an ECMA standard in 1997
- ECMA-262 is the official name of the standard
- ECMAScript is the official name of the language
How is JScript code inserted into a HTML page? (3)
- between < script > < / script > tags
- either in the < head > or at the end of the < body > section, or in both
- can be stored in external js.file and linked to
Why is it preferrable to include JavaScript code at the bottom of the < body > section?
~improves display time as script compilation slows down the display
Place a script code in the < body > changing the text of a paragraph into some other text if you press a button.
< button type=”button” onclick=”myFunction()” >Try it< / button >
< script >
function myFunction() {
document.getElementById(“demo”).innerHTML = “Paragraph changed.”;
}
< / script >
Put the link to an external JScript file “myScript.js” onto a homepage.
< body >
< script src=”myScript.js” >< / script >
< / body >
What are the advantages of using external .js files? (4)
- practical when the same code is used in many different web pages
- It separates HTML and code
- It makes HTML and JavaScript easier to read and maintain
- Cached JavaScript files can speed up page loads
What are the 4 different ways JS output can be displayed?
- Writing into an HTML element, using innerHTML.
- Writing into the HTML output using document.write().
- Writing into an alert box, using window.alert().
- Writing into the browser console, using console.log().
Use a simple example to show how innerHTML is used?
< p id=”test” >< / p >
< script >
document.getElementById(“test”).innerHTML = 5 + 6;
< / script >
Create an alert prompt with “Hello World!” displayed.
< script >
window.alert(“Hello World!”);
< / script >
Calculate 5 + 6 and display the result in the console.
< script >
console.log(5 + 6);
< / script >
Use document.write when clicking on a button, displaying “It’s all gone!”
< button onclick=”document.write(“It’s all gone!”) >Try it< / button >
- document.write after a page has fully loaded will erase all existing HTML
- use only for testing
JavaScript statements are composed of… (5)
- Values
- Operators
- Expressions
- Keywords
- Comments
The JavaScript syntax defines two types of values: … values and … values.
… values are called … … values are called …
Fixed, variable, Fixed, literals, Variable, variables.
What rules exist for literals in JScript?
- numbers can be written with or without decimals (type casting not required)
- strings can be written using double or single quotes
How are variables declared in JS?
-there are no types, all variables are declared with var
< script >
var x;
x = 6;
document.getElementById(“demo”).innerHTML = x;
< / script >
What can JScript expressions contain?
Values, variables, and operators.
Strings and operators: “John” + “ “ + “Doe
Variables and number literals: x + 10
How do you comment in JScript?
// for single line comments
/* */ for multiline comments
Are lastname and lastName the same thing?
No, JScript is case sensitive.
What is VAR?
A unique name; it is not the keyword var!
What character set does JScript use?
Unicode
Most JavaScript programs contain many JavaScript …
They are executed, one by one, in the … order as they are written.
JavaScript programs (and JavaScript statements) are often called …
statements, same, JavaScript code
The best place to break in a JScript statement is after …
…an operator.
What is the keyword break for?
Terminates a switch or a loop.