Uncategorized Flashcards

(55 cards)

1
Q

Inside which HTML element do we put the JavaScript?

A)
B)
C)
D)

A

C)

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

What is the correct JavaScript syntax to change the content of the HTML element below?

<p>This is a demonstration.</p>

A) document.getElementByName(“p”).innerHTML = “Hello World!”;
B) document.getElementById(“demo”).innerHTML = “Hello World!”;
C)#demo.innerHTML = “Hello World!”;
D)document.getElement(“p”).innerHTML = “Hello World!”;

A

B) document.getElementById(“demo”).innerHTML = “Hello World!”;

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

Where is the correct place to insert a JavaScript?

A) The section
B) The section
C) Both the section and the section are correct

A

C) Both the section and the section are correct

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

What is the correct syntax for referring to an external script called “xxx.js”?

A)
B)
C)


A

A)

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

The external JavaScript file must contain the tag.

A) True
B) False

A

B) False

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

How do you write “Hello World” in an alert box?

A) alert(“Hello World”);
B) msgBox(“Hello World”);
C) alertBox(“Hello World”);
D) msg(“Hello World”);

A

A) alert(“Hello World”);

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

How do you create a function in JavaScript?

A) function myFunction()
B) function = myFunction()
C) function:myFunction()

A

A) function myFunction()

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

How do you call a function named “myFunction”?

A) call function myFunction()
B) myFunction()
C) call myFunction()

A

B) myFunction()

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

How to write an IF statement in JavaScript?

A) if i == 5 then
B) if i = 5
C) if i = 5 then
D) if (i == 5)

A

D) if (i == 5)

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

How to write an IF statement for executing some code if “i” is NOT equal to 5?

A) if i <> 5
B) if (i != 5)
C) if (i <> 5)
D) if i =! 5 then

A

B) if (i != 5)

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

How does a WHILE loop start?

A) while (i <= 10)
B) while i = 1 to 10
C) while (i <= 10; i++)

A

A) while (i <= 10)

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

How does a FOR loop start?

A) for (i = 0; i <= 5)
B) for (i = 0; i <= 5; i++)
C) for i = 1 to 5
D) for (i <= 5; i++)

A

B) for (i = 0; i <= 5; i++)

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

How can you add a comment in a JavaScript?

A) ‘This is a comment
B)
C) //This is a comment

A

C) //This is a comment

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

How to insert a comment that has more than one line?

 A) //This comment has
more than one line//
 B) /*This comment has
more than one line*/
 C)
A

B) /*This comment has

more than one line*/

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

What is the correct way to write a JavaScript array?

 A) var colors = "red", "green", "blue"
 B) var colors = ["red", "green", "blue"]
 C) var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")
 D) var colors = (1:"red", 2:"green", 3:"blue")
A

B) var colors = [“red”, “green”, “blue”]

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

How do you round the number 7.25, to the nearest integer?

A) round(7.25)
B) rnd(7.25)
C) Math.round(7.25)
D) Math.rnd(7.25)

A

C) Math.round(7.25)

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

How do you find the number with the highest value of x and y?

A) Math.max(x, y)
B) top(x, y)
C) Math.ceil(x, y)
D) ceil(x, y)

A

A) Math.max(x, y)

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

What is the correct JavaScript syntax for opening a new window called “w2” ?

A) w2 = window.new(“http://www.w3schools.com”);
B) w2 = window.open(“http://www.w3schools.com”);

A

B) w2 = window.open(“http://www.w3schools.com”);

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

How can you detect the client’s browser name?

A) navigator.appName
B) client.navName
C) browser.name

A

A) navigator.appName

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

Which event occurs when the user clicks on an HTML element?

A) onmouseclick
B) onmouseover
C) onclick
D) onchange

A

C) onclick

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

What will the following code return: Boolean(10 > 9)

A) false
B) true
C) NaN

A

B) true

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

Is JavaScript case-sensitive?

A) Yes
B) No

A

A) Yes

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

Is JavaScript multi-threaded or single-threaded?

A) Single-threaded
B) Multi-threaded

A

A) Single-threaded

24
Q

How can you get the total number of arguments passed to a function?

A - Using args.length property

B - Using arguments.length property

C - Both of the above.

D - None of the above.

A

B - Using arguments.length property

25
Which built-in method removes the last element from an array and returns that element? A - last() B - get() C - pop() D - None of the above.
C - pop()
26
Which of the following function of Number object forces a number to display in exponential notation? A - toExponential() B - toFixed() C - toPrecision() D - toLocaleString()
A - toExponential()
27
What does the Number function do?
Number() function converts the object argument to a number that represents the object's value. If the value cannot be converted to a legal number, NaN is returned.
28
Which of the following function of String object returns a number indicating the Unicode value of the character at the given index? A - charAt() B - charCodeAt() C - concat() D - indexOf()
B - charCodeAt()
29
Which of the following function of String object returns a number indicating whether a reference string comes before or after or is the same as the given string in sort order? A - localeCompare() B - search() C - substr() D - concat()
A - localeCompare() Examples: // The letter "a" is before "c" yielding a negative value 'a'.localeCompare('c'); // -2 or -1 (or some other negative value) ``` // Alphabetically the word "check" comes after "against" yielding a positive value 'check'.localeCompare('against'); // 2 or 1 (or some other positive value) ``` ``` // "a" and "a" are equivalent yielding a neutral value of zero 'a'.localeCompare('a'); // 0 ``` ``` //use with sorting var items = ['réservé', 'premier', 'cliché', 'communiqué', 'café', 'adieu']; items.sort((a, b) => a.localeCompare(b)); // ['adieu', 'café', 'cliché', 'communiqué', 'premier', 'réservé'] ```
30
Which of the following function of String object returns the calling string value converted to upper case while respecting the current locale? A - toLocaleUpperCase() B - toUpperCase() C - toString() D - substring()
A - toLocaleUpperCase()
31
Which of the following function of String object causes a string to be displayed as struck-out text, as if it were in a tag? A - sup() B - small() C - strike() D - sub()
C - strike()
32
Which of the following function of Array object joins all elements of an array into a string? A - concat() B - join() C - pop() D - map()
B - join() ``` Ex: var a = ['Wind', 'Rain', 'Fire']; a.join(); // 'Wind,Rain,Fire' a.join(', '); // 'Wind, Rain, Fire' a.join(' + '); // 'Wind + Rain + Fire' a.join(''); // 'WindRainFire' ``` ``` //or with a function... function f(a, b, c) { var s = Array.prototype.join.call(arguments); console.log(s); // '1,a,true' } f(1, 'a', true); //expected output: "1,a,true" ```
33
Which of the following function of Array object sorts the elements of an array? A - toSource() B - sort() C - toString() D - unshift()
B - sort()
34
Which built-in method combines the text of two strings and returns a new string? A - append() B - concat() C - attach() D - None of the above.
B - concat()
35
Which of the following is the correct syntax to print a page using JavaScript? A - window.print(); B - browser.print(); C - navigator.print(); D - document.print();
window.print();
36
Which of the following function of String object returns the characters in a string between two indexes into the string? A - slice() B - split() C - substr() D - substring()
D - substring()
37
Which built-in method returns the calling string value converted to upper case? A - toUpperCase() B - toUpper() C - changeCase(case) D - None of the above.
A - toUpperCase()
38
Can you assign a anonymous function to a variable? A - true B - false
A - true
39
Which of the following function of String object returns a number indicating the Unicode value of the character at the given index? A - charAt() B - charCodeAt() C - concat() D - indexOf()
B - charCodeAt()
40
Can you access Cookie using javascript? A - true B - false
A - true
41
Which of the following type of variable is visible only within a function where it is defined? A - global variable B - local variable C - Both of the above. D - None of the above.
B - local variable
42
Which of the following is the correct syntax to create a cookie using JavaScript? A - document.cookie = 'key1 = value1; key2 = value2; expires = date'; B - browser.cookie = 'key1 = value1; key2 = value2; expires = date'; C - window.cookie = 'key1 = value1; key2 = value2; expires = date'; D - navigator.cookie = 'key1 = value1; key2 = value2; expires = date';
A - document.cookie = 'key1 = value1; key2 = value2; expires = date';
43
Which of the following function of Array object adds one or more elements to the front of an array and returns the new length of the array? A - unshift() B - sort() C - splice() D - toString()
A - unshift() ``` e.g. var arr = [1, 2]; ``` ``` arr.unshift(0); // result of call is 3, the new array length // arr is [0, 1, 2] ``` ``` arr.unshift(-2, -1); // = 5 // arr is [-2, -1, 0, 1, 2] ``` ``` arr.unshift([-3]); // arr is [[-3], -2, -1, 0, 1, 2] ```
44
Which of the following function of Array object returns true if at least one element in this array satisfies the provided testing function? A - reverse() B - shift() C - slice() D - some()
D - some()
45
Which of the following is true about variable naming conventions in JavaScript? A - You should not use any of the JavaScript reserved keyword as variable name. B - JavaScript variable names should not start with a numeral (0-9). C - Both of the above. D - None of the above.
C - Both of the above.
46
Which of the following function of String object is used to match a regular expression against a string? A - concat() B - match() C - search() D - replace()
B - match()
47
Which of the following function of Number object formats a number with a specific number of digits to the right of the decimal? A - toExponential() B - toFixed() C - toPrecision() D - toLocaleString()
B - toFixed() ``` e.g. var numObj = 12345.6789; ``` numObj.toFixed(); // Returns '12346': note rounding, no fractional part numObj.toFixed(1); // Returns '12345.7': note rounding numObj.toFixed(6); // Returns '12345.678900': note added zeros
48
Which of the following is true about variable naming conventions in JavaScript? A - JavaScript variable names must begin with a letter or the underscore character. B - JavaScript variable names are case sensitive. C - Both of the above. D - None of the above.
C - Both of the above.
49
Which of the following function of Boolean object returns a string containing the source of the Boolean object? A - toSource() B - valueOf() C - toString() D - None of the above.
A - toSource() Non-standard This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user.
50
Which of the following function of String object causes a string to be italic, as if it were in an tag? A - fixed() B - fontcolor() C - fontsize() D - italics()
D - italics() e.g. ``` var worldString = 'Hello, world'; console.log(worldString.italics()); // Hello, world ```
51
Which of the following code creates an object? A - var book = Object(); B - var book = new Object(); C - var book = new OBJECT(); D - var book = new Book();
B - var book = new Object();
52
Which of the following function of Array object returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found? A - indexOf() B - join() C - lastIndexOf() D - map()
C - lastIndexOf()
53
Which of the following type of variable is visible everywhere in your JavaScript code? A - global variable B - local variable C - Both of the above. D - None of the above.
A - global variable
54
Which of the following statements are true? A - JS can create cookies B - JS can react to events C - JS can read and write HTML elements D - All of the above
D - All of the above
55
Which statements are true? ``` A) '1' == 1 B) '1' === 1 C) false == 0 D) false === 0 E) false == '' F) false === '' G) 'abc' == 'abc' H) [1,2,3] == [1,2,3] ```
A, C, E, G Remember that === tests for identical equals. And in the case of [1,2,3] == [1,2,3], the equals can not test for equality with all the elements. It only tests on the object level.