WebDesign JScript Flashcards

1
Q

What is the history of JavaScript? (4)

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is JScript code inserted into a HTML page? (3)

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is it preferrable to include JavaScript code at the bottom of the < body > section?

A

~improves display time as script compilation slows down the display

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Place a script code in the < body > changing the text of a paragraph into some other text if you press a button.

A

< button type=”button” onclick=”myFunction()” >Try it< / button >

< script >
function myFunction() {
document.getElementById(“demo”).innerHTML = “Paragraph changed.”;
}
< / script >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Put the link to an external JScript file “myScript.js” onto a homepage.

A

< body >

< script src=”myScript.js” >< / script >

< / body >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the advantages of using external .js files? (4)

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the 4 different ways JS output can be displayed?

A
  • 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().
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Use a simple example to show how innerHTML is used?

A

< p id=”test” >< / p >

< script >
document.getElementById(“test”).innerHTML = 5 + 6;
< / script >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Create an alert prompt with “Hello World!” displayed.

A

< script >
window.alert(“Hello World!”);
< / script >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Calculate 5 + 6 and display the result in the console.

A

< script >
console.log(5 + 6);
< / script >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Use document.write when clicking on a button, displaying “It’s all gone!”

A

< 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JavaScript statements are composed of… (5)

A
  • Values
  • Operators
  • Expressions
  • Keywords
  • Comments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The JavaScript syntax defines two types of values: … values and … values.

… values are called … … values are called …

A

Fixed, variable, Fixed, literals, Variable, variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What rules exist for literals in JScript?

A
  • numbers can be written with or without decimals (type casting not required)
  • strings can be written using double or single quotes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How are variables declared in JS?

A

-there are no types, all variables are declared with var

< script >
var x;
x = 6;
document.getElementById(“demo”).innerHTML = x;
< / script >

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What can JScript expressions contain?

A

Values, variables, and operators.

Strings and operators: “John” + “ “ + “Doe

Variables and number literals: x + 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you comment in JScript?

A

// for single line comments

/* */ for multiline comments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Are lastname and lastName the same thing?

A

No, JScript is case sensitive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is VAR?

A

A unique name; it is not the keyword var!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What character set does JScript use?

A

Unicode

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

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 …

A

statements, same, JavaScript code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

The best place to break in a JScript statement is after …

A

…an operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the keyword break for?

A

Terminates a switch or a loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the continue keyword for?

A

Jumps out of a loop and starts at the top.

25
Q

What is the debugger keyword for?

A

Stops the execution of JavaScript, and calls (if available) the debugging function.

26
Q

What is the return keyword for?

A

Exits a function.

27
Q

All JavaScript variables must be identified with … Those names are called …

A

unique names, identifiers

28
Q

What are the rules for variable identifiers? (5)

A
  • can contain letters, digits, underscores, and dollar signs
  • must begin with a letter
  • can also begin with $ and _
  • names are case sensitive (y and Y are different variables)
  • reserved words (like JavaScript keywords) cannot be used as names
29
Q

Declare a variable with the value “Cheetah”.

A

var fastAnimal = “Cheetah”;

30
Q

Declare the following variables in one statement.

Amano

56 art books

price $112

A

var artist = “Amano”, booksPublished = 56, avePrice = 112;

OR

var artist = “Amano”,

booksPublished = 56,

avePrice =112;

31
Q

A variable that has no value declared has the value …

A

undefined

32
Q

Which arithmetic operators are allowed in JScript? (7)

A
  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Modulus
  • Increment
  • Decrement
33
Q

Give the 5 shortcut operators you can use in JScript.

A

x += y shortcut for x = x + y

x -= y shortcut for x = x - y

x *= y shortcut for x = x * y

x /= y shortcut for x = x / y

x %= y shortcut for x = x % y

34
Q

How can you use a shortcut operator to concatenate string?

We are gonna / party thru the night.

A

txt1 = “We are gonna “;
txt1 += “party thru the night.”;

35
Q

Which comparison operators does JScript know? (9)

A

== equal to

=== equal value and equal type

!= not equal

!== not equal value or not equal type

> greater than

< less than

>= greater than or equal to

<= less than or equal to

? ternary operator

36
Q

What logical operators does JScript know? (3)

A

&& logical and

|| logical or

! logical not

37
Q

What does typeof do?

A

Returns the type of a variable.

38
Q

What does instanceof do?

A

Returns true if an object is an instance of an object type.

39
Q

bitwise

A

bitwise

40
Q

The numbers (in an arithmetic operation) are called …

A

…operands.

41
Q

The operation (to be performed between the two operands) is defined by an …

A

…operator.

42
Q

What will be displayed?

var x = 97 + “Chicken”;

A

97Chicken

43
Q

JScript evaluates from … to …

What will be displayed?

var x = 13 + 8 + “Miami”;

A

left, right

21Miami

JScript first reaches the numbers and calculates 13 + 8. It then reaches the string “Miami” and converts all into a string.

44
Q

What will be displayed?

var x = “Baby” + 11 + 8;

A

Baby118

JScript first reaches the string. It then converts all into string, never calculating 11 * 8.

45
Q

How can you display quotes inside a string?

A

The quotes must not match!

var text = "The cat is called 'Pixie'"; 
var text = 'The cat is called "Pixie"';
46
Q

How do you break to a new line in a string?

A

< script >

var plant1 = “Clover”, plant2 = “Dandelion”;

document.getElementById(“test”).innerHTML =
plant1 + “
“ +
plant2;
var firstName = ‘Johnny’, lastName = ‘Flynn’, occupation = ‘Carpenter’;

document.getElementById(“demo”).innerHTML =
firstName + “ “ +
lastName + “
“ +
occupation;

< / script >

47
Q

How can you write the following numbers in scientific notation?

3670000000

0.000056

A

367e7

56e-6

48
Q

Write a simple array with the following items:

wallaby

kangaroo

koala

A

var aussieMammals = [“wallaby”, “kangaroo”, “koala”];

49
Q

Display the following list.

Jeep

Hummer

Landcruiser

A
\< script \>
var cars = ["Jeep","Hummer","Landcruiser"];

document.getElementById(“test”).innerHTML = cars[0] +

+ “< br >” + cars[1] + “< br >” + cars[2];
< / script >

50
Q

Declare an object, which has the following properties:

55-year-old man

Wayne Price

Cricket

green eyes

A

var person = {

firstName: “Wayne”,

lastName: “Price”,

Sex: “m”,

age: 55,

eyeColor: “green”,

favSport: “Cricket”};

51
Q

The typeof operator returns “…” for arrays because in JavaScript arrays are …

A

object, objects

52
Q

What is the difference between undefined and null? (3)

A

~ undefined’s type is undefined, null’s type is object

undefined == null yields “true”

undefined === null yields “false”

53
Q

What is the syntax of functions in JScript?

A

function name(parameter1, parameter 2, parametern) {

code to be executed

}

54
Q

Function arguments are the … received by the function when it is invoked.

Inside the function, the arguments (…) behave as … variables.

A Function is much the same as a … or a …, in other programming languages.

A

real values, the parameters, local, Procedure, Subroutine

55
Q

In JavaScript null is “…”. It is supposed to be something that doesn’t exist.

Unfortunately, in JavaScript, the data type of null is an …

You can consider it a … in JavaScript that typeof null is an … It should be null.

You can … an object by setting it to …

A

nothing, object, bug, object, empty, null or undefined

56
Q

When are JScript functions invoked? (3)

A
  • When an event occurs (when a user clicks a button)
  • When it is invoked (called) from JavaScript code
  • Automatically (self invoked)
57
Q

Create a very simple function “calculate” that calculates 4 * 3.

A

< script >

function calculate(a, b) {
 return a \* b;
}
document.getElementById("demo").innerHTML = myFunction(4, 3);
function someFunction(a,b) {

return a * b;

document.getElementById(“test”).innerHTML = (4,3);

< / script >

58
Q

Fix the function to display “Hello Scotty”.

< p id=”test” >Text text text.< / p >

< script >
function myFunction(name) {
return “Hello “ + name;
}
< / script >

function myFunction(name) {
 return "Hello " + name;
}
A

< p id=”test” >Text text text.< / p >

< script >
function myFunction(name) {
return “Hello “ + name;
}
document.getElementById(“test”).innerHTML = myFunction(“Scotty”);
< / script >

function myFunction(name) {
 return "Hello " + name;

}

document.getElementById(“test”).innerHTML = myFunction(“Scotty”);