JavaScript Flashcards

1
Q
How can you add new DIV elements dynamically?
Select one:
a. document.createDiv( )
b. document.newElement('div')
c. document.createElement('div') 
d. document.createNode('div')
A

c. document.createElement(‘div’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
The output of the go( ) function is \_\_\_\_\_ and the run( ) function is \_\_\_\_\_\_. 
html 
body
button onclick="go();" Go button
button onclick="run();" Run button 
body
script type="text/javascript" dan = 'Dan Pickles'; function go(){ alert( 'Hello ' + dan); } function run(){ alert(dan);}script
html
Select one:
a. Hello Dan Pickles, Dan Pickles 
b. Undefined, Undefined
c. Nothing, Nothing
d. Uncaught ReferenceError: dan is not defined, Uncaught ReferenceError: dan is not defined
e. Hello Dan Pickles, Undefined
f. Undefined, Dan Pickles
A

a. Hello Dan Pickles, Dan Pickles

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

We can add more than one ‘document.ready’ function in a page.
Select one:
a. False
b. True

A

b. True

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

What is === operator?
Select one:
a. Compares value equality as well as data type
b. Basic comparison operator
c. Basic assignment operator
d. Compares equality and, if equal, assigns the value of the left operator to the value of the right

A

a. Compares value equality as well as data type

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

What is not true about JavaScript?
Select one:
a. It is widely used for client side validation
b. JavaScript is a scripting language
c. Embedded in Netscape, Internet Explorer, and other web browsers
d. It is object-based, lightweight and cross platform
e. Able to build interactivity into otherwise static HTML pages
f. JavaScript relies on server-side technologies to manage cookies

A

f. JavaScript relies on server-side technologies to manage cookies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
What is the output of the following code: alert( isNaN('Dan') )
Select one:
a. True 
b. False
c. Null
d. Undefined
A

a. True

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

What is the output of the following code: window.onload = function a( ){ console.log(obj.prop); }
Select one:
a. None of these
b. Null
c. Undefined
d. Uncaught ReferenceError: obj is not defined

A

d. Uncaught ReferenceError: obj is not defined

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

What is the output of the following snippet assuming it is the only function in the script tag: window.onload = alert(dan);
Select one:
a. Dan
b. Undefined
c. None of the above
d. Uncaught ReferenceError: dan is not defined

A

d. Uncaught ReferenceError: dan is not defined

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

What is the output of the following snippet assuming it is the only function in the script tag: window.onload = function() {var dan; alert(dan);}
Select one:
a. Dan
b. None of the above
c. Undefined
d. Uncaught ReferenceError: dan is not defined

A

c. Undefined

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

Which code snippet will produce negative infinity?
Select one:
a. -10000000000000000000000 / -1000000000000000000000
b. 0 / -5
c. None of the above
d. -10 / 0

A

d. -10 / 0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
Which JavaScript timer will execute repeatedly until the function is cancelled?
Select one:
a. clearInterval
b. setTimer
c. setInterval 
d. setTimeout
A

c. setInterval

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
Which is not a JavaScript data type?
Select one:
a. Object
b. Null
c. String
d. Function
e. Undeclared 
f. Number
g. Boolean
A

e. Undeclared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
Which is not a JavaScript event?
Select one:
a. onhover
b. onload
c. onchange
d. onclick
e. None of these
A

a. onhover

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

Which will submit a form using JavaScript?
Select one:
a. document.getElementById(‘myform’).submit( )
b. document.submit( )
c. All of these
d. document.myForm.submit( )

A

a. document.getElementById(‘myform’).submit( )

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

What is the issue with using: typeof bar === “object” in order to determine if bar is an object?

A

By putting object in quotes, you’re saying that object is a String and since this is strict equals, data type matters, unlike ==, which will first convert both variables to the same datatype before doing a comparison on the references.

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

Match the correct this reference for each invocation form.

Apply Form
Constructor Form
Function Form
Method Form

The Global object
The newly created object
The object that owns the invoked function
The object passed in as a parameter

A

The correct answer is: Apply Form. – The object passed in as a parameter., Constructor Form. – The newly created object., Function Form – The global object., Method Form – The object that owns the invoked function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
What is the difference between:
document.getElementById( "logo" );
and
$( "#logo" );
Select one:
a. The first returns a list of elements while the second returns an element.
b. The second one is faster. 
c. The first returns an element while the second returns a list of elements.
d. There is no difference.
e. The first one is faster.
A

e. The first one is faster.

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

What is the output of the following code:
(function(){

var a = b = 3;

})();

console.log((typeof a === ‘number’) + “ - “ + (typeof b === ‘number’));

Select one:

a. false - false
b. true - true
c. false - true
d. true - false

A

c. false - true

19
Q
What is the output:
var x = 'hello' / 3;
console.log(x + ' - ' + typeof x);
Select one:
a. "hello" - string
b. undefined - undefined
c. NaN - object 
d. undefined - string
e. NaN - number
A

e. NaN - number

20
Q
What is the output?
function foo()
{
  return
  {
      bar: "hello"
  };
}
console.log(foo());
Select one:
a. undefined
b. Object {bar:"hello"}
c. "hello"
d. {}
e. null
A

a. undefined

21
Q

What is the output?

(function() {
console.log(1);
setTimeout(function(){console.log(2)}, 1000);
setTimeout(function(){console.log(3)}, 0);
console.log(4);
})();

Select one:

a. Nothing will output.
b. 1 2 3 4
c. 1 3 4 2
d. 1 3 2 4
e. 1 4 3 2

A

e. 1 4 3 2

22
Q

What is the output?

function Person(name, age){
    this.name = name;
    this.age = age;
    function getAge1(){
        return this.age;
    }
    this.getAge2 = function(){
        return getAge1();
    }
}
var john = new Person('John', 32);
console.log(john.getAge2());

Select one:

a. undefined
b. Compile Error
c. John
d. 32
e. Person {name:”John”, age:32}

A

a. undefined

23
Q

What is the output?

console.log(({}||false||{}||true)&&(new Boolean(false)&&'false'&&[]));
Select one:
a. {}
b. []
c. Compile Error
d. false 
e. Boolean {[[PrimitiveValue]] : false}
f. true
g. undefined
A

b. []

24
Q

What is the output?

var a={},
    b={key:'b'},
    c={key:'c'};

a[b]=123;
a[c]=456;

console.log(a[b]);
Select one:
a. 456
b. [object Object]
c. null
d. undefined
e. 123
A

a. 456

25
Q

What should be the name of this function?

function (x) { return (x^0) === x; } 
Select one:
a. isEven
b. isInteger
c. isString
d. isFloatingPoint
e. isBoolean
A

b. isInteger

26
Q

Which of the following is not one of the built in error types in JavaScript.

Select one:

a. SyntaxError
b. URIError
c. ReferenceError
d. TypeError
e. EvalError
f. CompileError
g. RangeError

A

f. CompileError

27
Q

Which one is not an invocation form in JavaScript?

Select one:

a. Constructor Form
b. Function Form
c. Apply Form
d. Method Form
e. Object Form

A

e. Object Form

28
Q

!== will perform type coercion.

Select one:
True
False

A

False

29
Q

.1+.2!==.3

Select one:
True
False

A

True

30
Q

== is equality comparison while === is identity comparison

Select one:
True
False

A

True

31
Q

In JavaScript, a closure is an inner function that has access to its outer function’s scope, even after the outer function has returned.

Select one:
True
False

A

True

32
Q

In JavaScript, Array inherits from Object.

Select one:
True
False

A

True

33
Q

In JavaScript, Function inherits from Object.

Select one:
True
False

A

True

34
Q

JavaScript code is compiled before being delivered to the browser (or other platform).

Select one:
True
False

A

False

35
Q

JavaScript has block (aka local) scope.

Select one:
True
False

A

False

36
Q

JavaScript has no types.

Select one:
True
False

A

False

37
Q

JSON is how JavaScript represents objects.

Select one:
True
False

A

False

38
Q

Most browsers have a debugger for JavaScript, which is extremely useful.
Select one:
True
False

A

True

39
Q

NaN === NaN

Select one:
True
False

A

False

40
Q

push adds an element to the beginning of an array.

Select one:
True
False

A

False

41
Q

shift removes the first element of an array and returns that element.

Select one:
True
False

A

True

42
Q

this is bound at invocation time.
Select one:
True
False

A

True

43
Q

When using JavaScript, the global object is always window.
Select one:
True
False

A

False

44
Q

You should write unobtrusive JavaScript.

Select one:
True
False

A

True