logo
  • Home
  • Test & Rank
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Mining
  • Marine
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Jobs
  • Contact

JavaScript Multiple Choice Questions | MCQs | Quiz

Javascript Interview Questions and Answers
Practice Javascript questions and answers for interviews, campus placements, online tests, aptitude tests, quizzes and competitive exams.

Get Started

•   Lexical Structure
•   Types, Values & Variables
•   Expressions & Operators
•   Statements
•   JavaScript Loops
•   Object Attributes
•   Array & Related Methods
•   Invoking Functions
•   Functional Programming
•   Closures
•   JavaScript Classes
•   Augmentation of Classes
•   JavaScript Modules
•   Pattern Matching
•   JavaScript Subsets
•   JavaScript Extentions
•   Shorthand Functions
•   Server-Side JavaScript
•   Scripting Java - Rhino
•   Asynchronous I/O - Rhino
•   Client-Side JavaScript
•   Embedding JavaScript
•   JavaScript-Web Browsers-1
•   JavaScript-Web Browsers-2
•   Client-Side Frameworks
•   Document Object Model
•   Window Object
•   Error Handling - 1
•   Error Handling - 2
•   Scripting Documents
•   Scripting CSS
•   Handling Events
•   Mouse Events
•   Text Events
•   Drag & Drop Events
•   Keyboard Events
•   Node Operations - 1
•   Node Operations - 2
•   Cookies
•   Scripted HTTP
•   The jQuery Library
•   Client-Side Storage
•   Client-Side Databases
•   Scripted Media
•   Graphics
•   Browser Rendering - 1
•   Browser Rendering - 2
•   JavaScript Performance - 1
•   JavaScript Performance - 2
•   JavaScript - FireBug
•   JavaScript - YSlow
•   JavaScript - WebPagetest
•   JavaScript Minification - 1
•   JavaScript Minification - 2
•   Web Sockets
•   JavaScript History
•   Getting Started with R - 1
•   Getting Started with R - 2
•   Getting Started with R - 3
•   Enhanced JavaScript with R
•   WebPagetest API Access
•   Configuration File Creation
•   Parsing Values - 1
•   Parsing Values - 2
•   JavaScript Benchmarking-1
•   JavaScript Benchmarking-2
•   Public API Crafting
•   Remote Logging
•   Object Invocation
•   PerfLogger Performance
•   Navigation & Memory - 1
•   Navigation & Memory - 2
•   BottleNecks Optimization
•   Script Loading - 1
•   Script Loading - 2
•   Lazy Loading - 1
•   Lazy Loading - 2
•   Cache Variable & Properties
•   Closure Compiler
•   Web Workers
•   JavaScript Blobs
•   JavaScript & Memory Leak
•   External JavaScript & PHP
•   HTML APIs
•   HTML DOM
•   Animation
•   Validation
•   Image Map
•   Debugging Forms
•   JavaScript vs Frameworks-1
•   JavaScript vs Frameworks-2

Best Reference Books

Javascript Books

JavaScript Tests

Certification Test
Internship Test
Job Test
All Tests
Top Rankers
Practice Test 1
Practice Test 2
Practice Test 3
Practice Test 4
Practice Test 5
Practice Test 6
Practice Test 7
Practice Test 8
Practice Test 9
Practice Test 10
Mock Test 1
Mock Test 2
Mock Test 3
Mock Test 4
Mock Test 5
Mock Test 6
Mock Test 7
Mock Test 8
Mock Test 9
Mock Test 10
« Prev Page
Next Page »

JavaScript Questions & Answers – Defining and Invoking Functions

Posted on August 29, 2013 by Manish

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Defining and Invoking Functions”.

1. The function definitions in JavaScript begins with _____________
a) Identifier and Parentheses
b) Return type and Identifier
c) Return type, Function keyword, Identifier and Parentheses
d) Identifier and Return type
View Answer

Answer: c
Explanation: The function definitions begin with the keyword function followed by an identifier that names the function and a pair of parentheses around a comma-separated list of zero or more identifiers.
advertisement

2. What will be the output of the following JavaScript code?

function printprops(o) 
{
    for(var p in o)
      console.log(p + ": " + o[p] + "\n");
}

a) Prints the contents of each property of o
b) Returns undefined
c) Prints only one property
d) Prints the address of elements
View Answer

Answer: b
Explanation: The above code snippet returns undefined.

3. When does the function name become optional in JavaScript?
a) When the function is defined as a looping statement
b) When the function is defined as expressions
c) When the function is predefined
d) when the function is called
View Answer

Answer: b
Explanation: The function name is optional for functions defined as expressions. A function declaration statement actually declares a variable and assigns a function object to it.

4. What is the purpose of a return statement in a function?
a) Returns the value and continues executing rest of the statements, if any
b) Returns the value and stops the program
c) Returns the value and stops executing the function
d) Stops executing the function and returns the value
View Answer

Answer: d
Explanation: The return stops the execution of the function when it is encountered within the function. It returns the value to the statement where the function is called.

5. What will happen if a return statement does not have an associated expression?
a) It returns the value 0
b) It will throw an exception
c) It returns the undefined value
d) It will throw an error
View Answer

Answer: c
Explanation: A function without a return statement will return a default value. If the return statement does not have an associated expression then it returns an undefined value.

6. A function with no return value is called ___________
a) Procedures
b) Method
c) Static function
d) Dynamic function
View Answer

Answer: a
Explanation: Void functions does not return a value. Functions with no return value are sometimes called procedures.

7. The function stops its execution when it encounters?
a) continue statement
b) break statement
c) goto statement
d) return statement
View Answer

Answer: d
Explanation: Continue statement and break statement are used in the loops for skipping the iteration or going out of the loop. Whenever a return statement is encountered the function execution is stopped.
advertisement

8. Which keyword is used to define the function in javascript?
a) void
b) int
c) function
d) main
View Answer

Answer: c
Explanation: A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses(). Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).

9. Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?
a) o(x,y);
b) o.m(x) && o.m(y);
c) m(x,y);
d) o.m(x,y);
View Answer

Answer: d
Explanation: The two argument in a function are separated by a comma (,). The code above is an invocation expression: it includes a function expression o.m and two argument expressions, x and y.

10. What will be the equivalent code of the following JavaScript code?

o.m(x,y);

a) o.m(x) && o.m(y);
b) o[“m”](x,y);
c) o(m)[“x”,”y”];
d) o.m(x && y);
View Answer

Answer: b
Explanation: Another way to write o.m(x,y) is o[“m”](x,y).o[“m”] will access the property of the object and parenthesis will access the function present inside it.

11. What will be the output of the following JavaScript code?

function info()
{  
    int a=1;
    int b=2;
    return a*b;  
}  
document.write(info());

a) 1
b) 2
c) 3
d) error
View Answer

Answer: b
Explanation: document.write() is used to write the output on the console. In the above code document.write() passes a function as its argument and the function returns 2 which is printed as output.
advertisement

12. What will be the output of the following JavaScript code?

var arr = [7, 5, 9, 1];  
var value = Math.max.apply(null, arr);  
document.writeln(value);

a) 7
b) 5
c) 1
d) 9
View Answer

Answer: d
Explanation: apply() is a predefined function method in javascript. The argument of apply() method contains elements of an array. It contains two values as argument which are optional as input.

13. What will be the output of the following JavaScript code?

var person = 
{  
      name: “Rahul”,  
      getName: function() 
      {  
          nreturn this.name;  
      }  
} 
var unboundName = person.getName;  
var boundName = unboundName.bind(person);  
document.writeln(boundName());

a) runtime error;
b) compilation error
c) Rahul
d) undefined
View Answer

Answer: c
Explanation: The javascript bind() function is used to create a new function. The newly created function has its own set of keywords.

14. What will be the output of the following JavaScript code?

function code(id,name) 
{  
  		this.id = id;   
  		this.name = name;  
}  
function pcode(id,name) 
{  
 		code.call(this,id,name);  
}
document.writeln(new pcode(101,"vivek").id);

a) vivek
b) 101
c) Runtime error
d) Compilation error
View Answer

Answer: b
Explanation: The JavaScript call() method is used to call a function containing “this” value as an argument. It returns the result of calling function.

15. What will be the output of the following JavaScript code?

     var pow=new Function("num1","num2","return Math.pow(num1,num2)");  
     document.writeln(pow(2,3));

a) 2
b) 3
c) 8
d) error
View Answer

Answer: c
Explanation: pow function is a predefined function which is present in the math library of javascript. The pow function accepts two arguments of which power of the first argument is calculated with respect to the second.

Sanfoundry Global Education & Learning Series – Javascript Programming.

To practice all areas of Javascript, here is complete set of 1000+ Multiple Choice Questions and Answers on Javascript.
« Prev Page - JavaScript Questions & Answers – Array and Related Methods
» Next Page - JavaScript Questions & Answers – Functions and Functional Programming

« JavaScript Questions & Answers – Array and Related Methods
JavaScript Questions & Answers – Functions and Functional Programming »
advertisement

Deep Dive @ Sanfoundry:

  1. C Programming Examples on Bitwise Operations
  2. C Questions and Answers
  3. Simple C Programs
  4. C Tutorials
  5. Simple Java Programs
  6. HTML Questions and Answers
  7. C Programming Examples on Mathematical Functions
  8. Java Programming Examples on Mathematical Functions
  9. C# Programming Examples on Functions
  10. Javascript Questions and Answers
Manish Bhojasia
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Facebook | Twitter

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
Terms
Privacy Policy
Jobs
Bangalore Training
Online Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry. All Rights Reserved.