JavaScript Questions & Answers – External JavaScript and PHP


This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “External JavaScript and PHP”.

1. In which format does JavaScript support external JavaScript?
a) .js
b) .php
c) .js/php
d) .jss
View Answer

Answer: a
Explanation: JavaScript supports external JavaScript, in the form of .js file. This extension can be captured by a number of applications including: Windows Script Host, Dreamweaver MX, Notepad, Netscape Navigator, PavScrip, UltraEdit. The files are generally text files.

2. What are the two parts of JavaScript libraries?
a) “script” tag and “body” tag
b) External JavaScript and the “script” tag
c) “html” tag and “body” tag
d) ”html” and “style” tag
View Answer

Answer: b
Explanation: All JavaScript libraries consists of two parts:

  • The external JavaScript itself, which is simply a text file with the containing JavaScript code, saved as a .js file.
  • A “script” tag referencing the external JavaScript file and defined on the page(s) that uses the library.

The <script> element either contains scripting statements, or it points to an external script file through the src attribute.


3. Which of the following is added to prefs.js when the console is automatically opened during JavaScript error?
a) user_pref(“javascript.console.open_on_error”, true);
b) user_pref(“javascript.console.open_error “, true);
c) user_pref(“javascript.console.open_error “, false);
d) user_pref(” javascript.console.open_on_error”, false);
View Answer

Answer: a
Explanation: The prefs.js file, located in the profile folder, is used by Firefox and other Mozilla-based applications to store settings. For instance, when you create a new e-mail account in Thunderbird, the account name and server settings will be stored in the prefs.js file in your Thunderbird profile folder.
The code :

user_pref("javascript.console.open_on_error", true);

is added to prefs.js when the console is automatically opened during JavaScript error.


4. Which of the following is possible to be referenced in external JavaScript?
a) CPP
b) Cs
c) PHP
d) Python
View Answer

Answer: c
Explanation: PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. One of the lesser known sides of external JavaScript is the ability to reference a PHP file instead of the familiar .js file.

5. Which of the following attribute takes the source of the PHP file?
a) img
b) src
c) source
d) psrc
View Answer

Answer: b
Explanation: Php file is used an scripting language for backend development. The syntax to referencing a PHP file using external JavaScript is consistent enough with what we already know:

<script type="text/javascript" src="myscript.php"></script>

6. What kind of path can the PHP file be?
a) Absolute
b) Relative
c) Either Absolute or Relative
d) Both Absolute and Relative
View Answer

Answer: c
Explanation: The PHP code is enclosed in special start and end processing instructions <?php and ?> that allows you to jump into and out of “PHP mode”. The PHP file is either an absolute or relative path to a PHP script instead of the usual .js file.

7. Which of the following global variables is used to get parameters?
View Answer

Answer: d
Explanation: The global variable $HTTP_GET_VARS[] is used to get parameters. $HTTP_GET_VARS contains the same initial information, but is not a superglobal.

8. What is the purpose of the RegExp method test()?
a) Tests for a match in its float parameter
b) Tests for a match in its string parameter
c) Tests for a match in its integer parameter
d) Test for a match in node
View Answer

Answer: b
Explanation: RegExp stands for regular expression which is an object that describes a pattern of characters.

9. What is the purpose of the function parameter filetype?
a) File type to be expected
b) File type previously got
c) File type that should not be got
d) File type available
View Answer

Answer: a
Explanation: The File.type property is an inbuilt function of File WebAPI which gives the media type (MIME) of the file represented by a file object. The function parameter “filetype” lets you tell the script what file type to expect before loading.

10. Which of the following is the method used to add an element to the desired location?
a) add.element()
b) element.add()
c) element.appendChild()
d) addelement()
View Answer

Answer: c
Explanation: The method element.appendChild() is used to add the element to the desired location within the document tree. The appendChild() method appends a node as the last child of a node.

Sanfoundry Global Education & Learning Series – Javascript Programming.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Manish Bhojasia - Founder & CTO at Sanfoundry
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 | Youtube | Instagram | Facebook | Twitter