WebDesign JScript Flashcards Preview

Cert IV Programming > WebDesign JScript > Flashcards

Flashcards in WebDesign JScript Deck (58):
1

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

2

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

3

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

4

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 >

 

 

 

5

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

< body >

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

< / body >

6

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

 

7

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

8

Use a simple example to show how innerHTML is used?

< p id="test" >< / p >

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

9

Create an alert prompt with "Hello World!" displayed.

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

10

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

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

11

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

 

12

JavaScript statements are composed of... (5)

  • Values
  • Operators
  • Expressions
  • Keywords
  • Comments

13

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

... values are called ... ... values are called ...

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

14

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

15

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 >

16

What can JScript expressions contain?

Values, variables, and operators.

 

Strings and operators: "John" + " " + "Doe

Variables and number literals: x + 10

17

How do you comment in JScript?

// for single line comments

/*  */ for multiline comments

18

Are lastname and lastName the same thing?

No, JScript is case sensitive.

19

What is VAR?

A unique name; it is not the keyword var!

20

What character set does JScript use?

Unicode

21

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

22

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

...an operator.

23

What is the keyword break for?

Terminates a switch or a loop.

24

What is the continue keyword for?

Jumps out of a loop and starts at the top.

25

What is the debugger keyword for?

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

26

What is the return keyword for?

Exits a function.

27

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

unique names, identifiers

28

What are the rules for variable identifiers? (5)

  • 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

Declare a variable with the value "Cheetah".

var fastAnimal = "Cheetah";

30

Declare the following variables in one statement.

Amano

56 art books

price $112

var artist = "Amano", booksPublished = 56, avePrice = 112;

OR

var artist = "Amano",

booksPublished = 56,

avePrice =112;

31

A variable that has no value declared has the value ...

undefined

32

Which arithmetic operators are allowed in JScript? (7)

  • Addition
  • Subtraction
  • Multiplication
  • Division
  • Modulus
  • Increment
  • Decrement

33

Give the 5 shortcut operators you can use in JScript.

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

How can you use a shortcut operator to concatenate string?

 

We are gonna / party thru the night.

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

35

Which comparison operators does JScript know? (9)

==    equal to

===  equal value and equal type

!=     not equal

!==   not equal value or not equal type

>      greater than

>=    greater than or equal to

<=    less than or equal to

?      ternary operator

 

36

What logical operators does JScript know? (3)

&&     logical and

||         logical or

!          logical not

37

What does typeof do?

Returns the type of a variable.

38

What does instanceof do?

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

39

bitwise

bitwise

40

The numbers (in an arithmetic operation) are called ...

...operands.

41

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

...operator.

42

What will be displayed?

var x = 97 + "Chicken";

97Chicken

43

JScript evaluates from ... to ...

 

What will be displayed?

 

var x = 13 + 8 + "Miami";

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

What will be displayed?

 

var x = "Baby" + 11 + 8;

Baby118

 

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

45

How can you display quotes inside a string?

The quotes must not match!

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

46

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

< 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

How can you write the following numbers in scientific notation?

 

3670000000

0.000056

367e7

56e-6

48

Write a simple array with the following items:

wallaby

kangaroo

koala

var aussieMammals = ["wallaby", "kangaroo", "koala"];

49

Display the following list.

Jeep

Hummer

Landcruiser

 

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

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

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

 

50

Declare an object, which has the following properties:

 

55-year-old man

Wayne Price

Cricket

green eyes

var person = {

firstName:   "Wayne",

lastName:    "Price",

Sex:              "m",

age:              55,

eyeColor:     "green",

favSport:      "Cricket"};

51

The typeof operator returns "..." for arrays because in JavaScript arrays are ...

object, objects

52

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

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

undefined == null yields "true"

undefined === null yields "false"

53

What is the syntax of functions in JScript?

function name(parameter1, parameter 2, parametern) {

code to be executed

}

54

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.

real values, the parameters, local, Procedure, Subroutine

55

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

 

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

56

When are JScript functions invoked? (3)

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

57

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

< 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

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;
}

< 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");