JavaScript Flashcards
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')
c. document.createElement(‘div’)
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. Hello Dan Pickles, Dan Pickles
We can add more than one ‘document.ready’ function in a page.
Select one:
a. False
b. True
b. True
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. Compares value equality as well as data type
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
f. JavaScript relies on server-side technologies to manage cookies
What is the output of the following code: alert( isNaN('Dan') ) Select one: a. True b. False c. Null d. Undefined
a. True
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
d. Uncaught ReferenceError: obj is not defined
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
d. Uncaught ReferenceError: dan is not defined
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
c. Undefined
Which code snippet will produce negative infinity?
Select one:
a. -10000000000000000000000 / -1000000000000000000000
b. 0 / -5
c. None of the above
d. -10 / 0
d. -10 / 0
Which JavaScript timer will execute repeatedly until the function is cancelled? Select one: a. clearInterval b. setTimer c. setInterval d. setTimeout
c. setInterval
Which is not a JavaScript data type? Select one: a. Object b. Null c. String d. Function e. Undeclared f. Number g. Boolean
e. Undeclared
Which is not a JavaScript event? Select one: a. onhover b. onload c. onchange d. onclick e. None of these
a. onhover
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. document.getElementById(‘myform’).submit( )
What is the issue with using: typeof bar === “object” in order to determine if bar is an object?
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.
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
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.
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.
e. The first one is faster.
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
c. false - true
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
e. NaN - number
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. undefined
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
e. 1 4 3 2
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. undefined
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
b. []
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. 456
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
b. isInteger
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
f. CompileError
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
e. Object Form
!== will perform type coercion.
Select one:
True
False
False
.1+.2!==.3
Select one:
True
False
True
== is equality comparison while === is identity comparison
Select one:
True
False
True
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
True
In JavaScript, Array inherits from Object.
Select one:
True
False
True
In JavaScript, Function inherits from Object.
Select one:
True
False
True
JavaScript code is compiled before being delivered to the browser (or other platform).
Select one:
True
False
False
JavaScript has block (aka local) scope.
Select one:
True
False
False
JavaScript has no types.
Select one:
True
False
False
JSON is how JavaScript represents objects.
Select one:
True
False
False
Most browsers have a debugger for JavaScript, which is extremely useful.
Select one:
True
False
True
NaN === NaN
Select one:
True
False
False
push adds an element to the beginning of an array.
Select one:
True
False
False
shift removes the first element of an array and returns that element.
Select one:
True
False
True
this is bound at invocation time.
Select one:
True
False
True
When using JavaScript, the global object is always window.
Select one:
True
False
False
You should write unobtrusive JavaScript.
Select one:
True
False
True