Exam Software
Exam Software
1. Which one of the following is the very first task executed by a session enabled page?
View Answer
Answer: c
Explanation: The session variables are set with the PHP global variable which is $_SESSION. The very first
task executed by a session enabled page is Check whether a valid session exists.
a) 3
b) 4
c) 5
d) 6
View Answer
Answer: b
Explanation: Within flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or
through user defined functions(user).
a) save_data
b) session.save
c) session.save_data
d) session.save_handler
View Answer
Answer: d
Explanation: The class SessionHandler is used to wrap whatever internal save handler is set as defined by
the session.save_handler configuration directive which is usually files by default.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
a) PHPSESSID
b) PHPSESID
c) PHPSESSIONID
d) PHPIDSESS
View Answer
Answer: a
Explanation: You can change this name by using the session.name directive.
a) Session
b) Cookie
c) URL rewriting
d) Nothing happens
View Answer
Answer: c
Explanation: The URL rewriting allows to completely separate the URL from the resource. URL rewriting
can turn unsightly URLs into nice ones with a lot less agony and expense than picking a good domain
name. It enables to fill out your URLs with friendly, readable keywords without affecting the underlying
structure of pages.
6. If the directive session.cookie_lifetime is set to 3600, the cookie will live until ____________
a) 3600 sec
b) 3600 min
c) 3600 hrs
View Answer
Answer: a
Explanation: The lifetime is specified in seconds, so if the cookie should live 1 hour, this directive should
be set to 3600.
7. Neglecting to set which of the following cookie will result in the cookie’s domain being set to the host
name of the server which generated it.
a) session.domain
b) session.path
c) session.cookie_path
d) session.cookie_domain
View Answer
Answer: d
Explanation: The directive session.cookie_domain determines the domain for which the cookie is valid.
8. What is the default number of seconds that cached session pages are made available before the new
pages are created?
a) 360
b) 180
c) 3600
d) 1800
View Answer
Answer: b
9. What is the default time(in seconds) for which session data is considered valid?
a) 1800
b) 3600
c) 1440
d) 1540
View Answer
Answer: c
Explanation: The session.gc_maxlifetime directive determines this duration. It can be set to any required
value.
a) start_session()
b) session_start()
c) session_begin()
d) begin_session()
View Answer
Answer: b
Explanation: A session is started with the function session_start() . The session variables are set with the
PHP global variable which is $_SESSION.
This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Session Handling-2”.
1. Which function is used to erase all session variables stored in the current session?
a) session_destroy()
b) session_change()
c) session_remove()
d) session_unset()
View Answer
Answer: d
Explanation: The function session_unset() frees all session variables that is currently registered. This will
not completely remove the session from the storage mechanism. If you want to completely destroy the
session, you need to use the function session_destroy().
View Answer
Answer: a
Explanation: The function session_id() will return the session id for the current session or the empty
string (” “) if there is no current session.
3. Which one of the following statements should you use to set the session username to Nachi?
a) $SESSION[‘username’] = “Nachi”;
b) $_SESSION[‘username’] = “Nachi”;
c) session_start(“nachi”);
d) $SESSION_START[“username”] = “Nachi”;
View Answer
Answer: b
Explanation: You need to refer the session variable ‘username’ in the context of the $_SESSION
superglobal.
advertisement
4. What will be the output of the following PHP code? (Say your previous session username was nachi.)
unset($_SESSION['username']);
d) Error
View Answer
Answer: c
Explanation: If someone want to destroy a single session variable then they can use the function unset ()
to unset a session variable. To delete the session variable ‘username’ we use the unset () function.
5. An attacker somehow obtains an unsuspecting user’s SID and then using it to impersonate the user in
order to gain potentially sensitive information. This attack is known as __________
a) session-fixation
b) session-fixing
c) session-hijack
d) session-copy
View Answer
Answer: a
Explanation: The attack session fixation attempts to exploit the vulnerability of a system that allows one
person to set another person’s session identifier. You can minimize this risk by regenerating the session
ID on each request while maintaining the session-specific data. PHP offers a convenient function named
session_regenerate_id() that will replace the existing ID with a new one.
6. Which parameter determines whether the old session file will also be deleted when the session ID is
regenerated?
a) delete_old_file
b) delete_old_session
c) delete_old_session_file
d) delete_session_file
View Answer
Answer: b
Explanation: The parameter delete_old_session determines whether the old session file will also be
deleted when the session ID is regenerated.
a) session_delete()
b) session_destroy()
c) session_garbage_collect()
d) SessionHandler::gc
View Answer
Answer: d
8. Which function is used to transform PHP’s session-handler behavior into that defined by your custom
handler?
a) session_set_save()
b) session_set_save_handler()
c) Session_handler()
d) session_save_handler()
View Answer
Answer: b
Explanation: The function session_set_save_handler() is used to set the user-level session storage
functions which are used for storing and retrieving data associated with a session.
View Answer
Answer: d
a) boolean
b) integer
c) float
d) character
View Answer
Answer: a
1. Which directive determines whether PHP scripts on the server can accept file uploads?
a) file_uploads
b) file_upload
c) file_input
d) file_intake
View Answer
Answer: a
Explanation: With PHP, it is easy to upload files to the server. We need to ensure that PHP is configured
to allow file uploads. In the “php.ini” file, search for the file_uploads directive, and set it to On. By
default, its value is on.
2. Which of the following directive determines the maximum amount of time that a PHP script will spend
attempting to parse input before registering a fatal error?
a) max_take_time
b) max_intake_time
c) max_input_time
d) max_parse_time
View Answer
Answer: c
Explanation: This is relevant because particularly large files can take some time to upload, eclipsing the
time set by this directive.
a) 30 seconds
b) 60 seconds
c) 120 seconds
d) 1 second
View Answer
Answer: b
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
4. Since which version of PHP was the directive max_file_limit available.
a) PHP 5.2.1
b) PHP 5.2.2
c) PHP 5.2.12
d) PHP 5.2.21
View Answer
Answer: c
Explanation: The max_file_limit directive sets an upper limit on the number of files which can be
simultaneously uploaded.
a) 10 files
b) 15 files
c) 20 files
d) 25 files
View Answer
6. Which directive sets a maximum allowable amount of memory in megabytes that a script can allow?
a) max_size
b) post_max_size
c) max_memory_limit
d) memory_limit
View Answer
Answer: d
7. If you want to temporarily store uploaded files in the /tmp/phpuploads/ directory, which one of the
following statement will you use?
View Answer
Answer: a
Explanation: Anyone can temporarily store uploaded files on the given directory. One cannot change
upload_tmp_dir at the runtime. By the time a script runs, the upload process has already occurred.
8. Which superglobal stores a variety of information pertinent to a file uploaded to the server via a PHP
script?
a) $_FILE Array
b) $_FILES Array
c) $_FILES_UPLOADED Array
d) $_FILE_UPLOADED Array
View Answer
Answer: b
Explanation: The superglobal $_FILES is a two-dimensional associative global array of items which are
being uploaded by via HTTP POST method and holds the attributes of files.
a) 2
b) 3
c) 4
d) 5
View Answer
Answer: d
a) is_file_uploaded()
b) is_uploaded_file()
c) file_uploaded(“filename”)
d) uploaded_file(“filename”)
View Answer
Answer: b
Explanation: The function is_uploaded_file() checks whether the specified file is uploaded via HTTP POST.
The syntax is is_uploaded_file(file).
« PrevNext »
This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Session Handling”.
1. Which one of the following is the very first task executed by a session enabled page?
View Answer
Answer: c
Explanation: The session variables are set with the PHP global variable which is $_SESSION. The very first
task executed by a session enabled page is Check whether a valid session exists.
a) 3
b) 4
c) 5
d) 6
View Answer
Answer: b
Explanation: Within flat files(files), within volatile memory(mm), using the SQLite database(sqlite), or
through user defined functions(user).
a) save_data
b) session.save
c) session.save_data
d) session.save_handler
View Answer
Answer: d
Explanation: The class SessionHandler is used to wrap whatever internal save handler is set as defined by
the session.save_handler configuration directive which is usually files by default.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
a) PHPSESSID
b) PHPSESID
c) PHPSESSIONID
d) PHPIDSESS
View Answer
Answer: a
Explanation: You can change this name by using the session.name directive.
a) Session
b) Cookie
c) URL rewriting
d) Nothing happens
View Answer
6. If the directive session.cookie_lifetime is set to 3600, the cookie will live until ____________
a) 3600 sec
b) 3600 min
c) 3600 hrs
d) the browser is restarted
View Answer
Answer: a
Explanation: The lifetime is specified in seconds, so if the cookie should live 1 hour, this directive should
be set to 3600.
7. Neglecting to set which of the following cookie will result in the cookie’s domain being set to the host
name of the server which generated it.
a) session.domain
b) session.path
c) session.cookie_path
d) session.cookie_domain
View Answer
Answer: d
Explanation: The directive session.cookie_domain determines the domain for which the cookie is valid.
8. What is the default number of seconds that cached session pages are made available before the new
pages are created?
a) 360
b) 180
c) 3600
d) 1800
View Answer
Answer: b
a) 1800
b) 3600
c) 1440
d) 1540
View Answer
Answer: c
Explanation: The session.gc_maxlifetime directive determines this duration. It can be set to any required
value.
a) start_session()
b) session_start()
c) session_begin()
d) begin_session()
View Answer
Answer: b
Explanation: A session is started with the function session_start() . The session variables are set with the
PHP global variable which is $_SESSION.
« PrevNext »
This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Functions”.
View Answer
Answer: d
Explanation: PHP allows us to create our own user-defined functions. Any name ending with an open and
closed parenthesis is a function. The keyword function is always used to begin a function.
a) PHP 4
b) PHP 5
c) PHP 5.3
d) PHP 6
View Answer
Answer: b
Explanation: PHP 5 introduced the feature of type hinting. With the help of type hinting, we can specify
the expected data type of an argument in a function declaration. First valid types can be the class names
for arguments that receive objects and the other are array for those that receive arrays.
3. Which type of function call is used in line 8 in the following PHP code?
advertisement
<?php
{
$total = $price + $tax;
$pricetag = 15;
$taxtag = 3;
calc($pricetag, $taxtag);
?>
a) Call By Value
b) Call By Reference
d) Type Hinting
View Answer
Answer: a
Explanation: If we call a function by value, we actually pass the values of the arguments which are stored
or copied into the formal parameters of the function. Hence, the original values are unchanged only the
parameters inside the function changes.
<?php
echo "$total";
calc(42);
?>
a) Error
b) 0
c) 42
d) 84
View Answer
Answer: c
Explanation: You can designate certain arguments as optional by placing them at the end of the list and
assigning them a default value of nothing.
i) function()
ii) €()
iii) .function()
iv) $function()
a) Only i)
b) Only ii)
c) i) and ii)
View Answer
Answer: b
Explanation: A valid function name can start with a letter or underscore, followed by any number of
letters, numbers, or underscores. According to the specified regular expression ([a-zA-Z_\x7f-\xff][a-zA-
Z0-9_\x7f-\xff]*), a function name like this one is valid.
6. What will be the output of the following PHP code?
<?php
function a()
function b()
a();
a();
?>
a) I am a
b) I am bI am a
c) Error
d) I am a Error
View Answer
Answer: a
Explanation: The output will be “I am a” as we are calling a(); so the statement outside the block of
function b() will be called.
function a()
function b()
b();
a();
?>
a) I am b
b) I am bI am a
c) Error
d) I am a Error
View Answer
Answer: c
Explanation: The output will be Fatal error: Call to undefined function b(). You cannot call a function
which is inside a function without calling the outside function first. It should be a(); then b();
<?php
$op2 = "blabla";
function foo($op1)
echo $op1;
echo $op2;
foo("hello");
?>
a) helloblabla
b) Error
c) hello
d) helloblablablabla
View Answer
Answer: c
Explanation: If u want to put some variables in function that was not passed by it, you must use “global”.
Inside the function type global $op2.
a) Magic Function
b) Inbuilt Function
c) Default Function
View Answer
Answer: a
Explanation: PHP functions that start with a double underscore – a “__” – are called magic functions in
PHP. They are functions that are always defined inside classes, and are not stand-alone functions.
10. What will be the output of the following PHP code?
<?php
function foo($msg)
echo "$msg";
$var1 = "foo";
?>
a) Error
b) $msg
c) 0
View Answer
Answer: d
Explanation: It is possible to call a function using a variable which stores the function name.
Internship
Training
Videos
Books
Contact
« PrevNext »
This set of JavaScript Interview Questions and Answers focuses on “JavaScript in Web Browsers – II”.
a) timestamp.Child1
b) timestamp.Child(1)
c) timestamp.Child(0)
d) timestamp.firstChild
View Answer
Answer: d
Explanation: The first child of a node can be accessed using the firstChild property. firstChild returns the
first child node as an element node, a text node or a comment node (depending on which one’s first).
2. What are the properties supporting CSS styles for a document element?
View Answer
Answer: b
Explanation: Each Element object has style and className properties that allow scripts to specify CSS
styles for a document element or to alter the CSS class names that apply to the element. firstChild returns
the first child node as an element node, a text node or a comment node (depending on which one’s first).
a) Element
b) Window
c) Location
d) Dynamic
View Answer
Answer: a
Explanation: Each Element object has style and className properties that allow scripts to specify CSS
styles for a document element or to alter the CSS class names that apply to the element.
advertisement
View Answer
Answer: c
Explanation: Event handlers allow JavaScript code to alter the behavior of windows, of documents, and of
the elements that make up those documents.
5. Which handler is triggered when the content of the document in the window is stable and ready for
manipulation?
a) onload
b) manipulate
c) create
d) onkeypress
View Answer
Answer: a
Explanation: One of the most important event handlers is the onload handler of the Window object. It is
triggered when the content of the document displayed in the window is stable and ready to be
manipulated. JavaScript code is commonly wrapped within an onload event handler.
6. When a program contains extensive use of event handlers, which of the following is necessary?
a) Modular functions
b) Nested functions
c) Split up programs
d) Global variables
View Answer
Answer: b
Explanation: Nested functions are those functions in which one function is defined inside another
function. Nested functions are common in client-side JavaScript, because of its extensive use of event
handlers.
7. What is the JavaScript code snippet to find all container elements with class “reveal”?
View Answer
Answer: a
Explanation: The getElementsByClassName() method returns a collection of all elements in the document
with the specified class name, as a NodeList object. The above code snippet finds all container elements
with class “reveal”.
8. What is the JavaScript code snippet to update the content of the timestamp element when the user
clicks on it?
View Answer
Answer: b
Explanation: onclick() function is used to handle events when the user clicks on the mouse. The above
code snippet updates the content of the timestamp element when the user clicks on it.
a) Element
b) Location
c) Position
d) Window
View Answer
Answer: c
Explanation: There is no object called Position. Whereas elements, location and window are a predefined
object in JavaScript.
10. What is the JavaScript code snippet to change the class and let the stylesheet specify the details?
a) timestamp.className = “highlight”;
b) timestamp.className = “change”;
c) timestamp.className = “specify”;
d) timestamp.className = “move”;
View Answer
Answer: a
Explanation: Each Element object has style and className properties that allow scripts to specify CSS
styles for a document element or to alter the CSS class names that apply to the element. The above code
snippet changes the class and lets the stylesheet specify the details.
« PrevNext »
This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Client-Side JavaScript”.
b) User Interface
c) Visual effects
d) User experience
View Answer
Answer: a
Explanation: JavaScript can help to facilitate that experience, for example by:
Creating animations and other visual effects to subtly guide a user and help with page navigation
Sorting the columns of a table to make it easier for a user to find what she needs
2. A JavaScript program can traverse and manipulate document content through __________
a) Element Object
b) Document Object
c) Both Element and Document Object
d) Data object
View Answer
Answer: c
Explanation: A JavaScript program can traverse and manipulate document content through the
Document object and the Element objects it contains. It can alter the presentation of that content by
scripting CSS styles and classes. The Element object represents an HTML element, like P, DIV, A, TABLE, or
any other HTML element.
View Answer
Answer: b
Explanation: The JavaScript program can define the behavior of document elements by registering
appropriate event handlers. A JavaScript program can traverse and manipulate document content
through the Document object and the Element objects it contains.
advertisement
4. The service(s) that enables networking through scripted HTTP requests is __________
a) XMLHttpResponse
b) XMLRequest
c) XMLHttpRequest
d) XMLHttps
View Answer
Answer: c
Explanation: The best known advanced services is the XMLHttpRequest object, which enables networking
through scripted HTTP requests. The XMLHttpRequest object can be used to request data from a web
server.
a) Data storage
b) Graphics APIs
d) Networking
View Answer
Answer: d
Explanation: The HTML5 specification (which, at the time of this writing, is still in draft form) and related
specifications are defining a number of other important APIs for web apps. These include data storage
and graphics APIs.The data storage api can store data locally within the user’s browser.
a) Data storage
b) Networking
c) XMLHttpRequest object
d) Graphics APIs
View Answer
Answer: d
Explanation: Data storage is used to store data locally on user’s computer and networking is used for
connecting between different platforms.
a) Non-inline
b) External
c) Referenced
d) Inline
View Answer
Answer: d
Explanation: The <script> tag is used to define a client-side script (JavaScript). The <script> element either
contains scripting statements, or it points to an external script file through the src attribute. Inline code
are those that are written between a pair of “script” tags.
View Answer
Answer: c
Explanation: The Client-side JavaScript code is embedded within HTML documents in four ways :
a) Unobtrusive JavaScript
b) Obtrusive JavaScript
c) Inherited JavaScript
d) Modular JavaScript
View Answer
Answer: a
Explanation: A programming philosophy known as unobtrusive JavaScript argues that content (HTML) and
behavior (JavaScript code) should as much as possible be kept separate. According to this programming
philosophy, JavaScript is best embedded in HTML documents using “script” elements with src attributes.
10. Which of the following communicates with server-side CGI scripts through HTML form submissions
and can be written without the use of JavaScript?
View Answer
Answer: b
Explanation: An interactive web page can dynamically vary its content based on user preferences.
Interactive web pages that communicate with server-side CGI scripts through HTML form submissions
were the original “web application” and can be written without the use of JavaScript.
« PrevNext »
This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Client-Side Databases”.
1. The Client-Side Databases are stored in the ____________
b) User’s computer
d) In the server
View Answer
Answer: b
Explanation: The actual client-side databases are stored on the user’s computer and are directly accessed
by JavaScript code in the browser.
a) Chrome
b) Firefox
c) IE
d) Firefox & IE
View Answer
Answer: a
Explanation: Chrome, Safari, and Opera implemented the Web SQL Database API, but Firefox and IE have
not, and likely never will.
3. Which of the following are objective database and not a relational database?
b) FileSystem API
c) IndexedDB
d) User data
View Answer
Answer: c
Explanation: IndexedDB is an object database, not a relational database, and it is much simpler than
databases that support SQL queries. It is more powerful, efficient, and robust than the key/value storage
provided by the Web Storage API, however.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
a) A collection of objects
c) Objects collection
d) Data collection
View Answer
Answer: b
Explanation: In the IndexedDB API, a database is simply a collection of named object stores.
c) A value that tells the database how to extract an object’s key from the object
View Answer
Answer: c
Explanation: A key path is defined as a value that tells the database how to extract an object’s key from
the object.
d) Interlinking data
View Answer
Answer: b
Explanation: IndexedDB provides atomicity guarantees: queries and updates to the database are grouped
within a transaction so that they all succeed together or all fail together and never leave the database in
an undefined partially updated state.
View Answer
Answer: a
Explanation: One of the convenient feature of the IndexedDB API is that it simplifies the transaction
management.
a) Key
b) Address
c) Indexes
d) Values
View Answer
Answer: c
Explanation: In addition to retrieving objects from an object store by their primary key value, you may
want to be able to search based on the value of other properties in the object. In order to be able to do
this, you can define any number of indexes on the object store.
a) put()
b) set()
c) get()
d) look()
View Answer
Answer: c
Explanation: You look up an object by calling the get() method of the object store or store a new object
by calling put().
10. Which is the method to look up the objects for a range of keys?
a) lookRange()
b) openCursor()
c) lookall()
d) look()
View Answer
Answer: b
Explanation: If you want to look up the objects for a range of keys, you create an IDBRange object and
pass it to the openCursor() method of the
1. What is PHP?
View Answer
Answer: d
Explanation: PHP is an open-source server-side scripting language that is used to build dynamic and
interactive web pages or web applications.
a) Drek Kolkevi
b) Rasmus Lerdorf
c) Willam Makepiece
d) List Barely
View Answer
Answer: b
View Answer
Answer: c
Explanation: PHP previously stood for Personal Home Page now stands for “Hypertext Preprocessor”.
a) <?php ?>
d) <? ?>
View Answer
Answer: d
Explanation: Every section of PHP code starts and ends by turning on and off PHP tags to let the server
know that it needs to execute the PHP in between them.
5. Which of the following is the correct way to add a comment in PHP code?
a) #
b) //
c) /* */
View Answer
Answer: d
Explanation: In PHP, /* */ can also be used to comment just a single line although it is used for
paragraphs. // and # are used only for single-line comments.
advertisement
a) .php
b) .ph
c) .xml
d) .html
View Answer
Answer: a
View Answer
Answer: c
Explanation: PHP allows us to create our own user-defined functions. Any name ending with an open and
closed parenthesis is a function. The keyword function is always used to begin a function.
<?php
$x = 10;
$y = 20;
else
?>
a) no output
b) Welcome to Sanfoundry
d) error
View Answer
Answer: c
Output:
a) $3hello
b) $_hello
c) $this
d) $5_Hello
View Answer
Answer: b
Explanation: A variable in PHP can not start with a number, also $this is mainly used to refer properties of
a class so we can’t use $this as a user defined variable name.
<?php
?>
a) 6
b) 5
c) 4
d) 3
View Answer
Answer: a
Explanation: function count() will return the number of elements in an array. The parameter 1 counts the
array recursively i.e it will count all the elements of multidimensional arrays.
<?php
function multi($num)
if ($num == 3)
if ($num == 7)
if ($num == 19)
multi($can);
?>
a) Correct Answer
b) Is The
c) I Wonder
d) Which One
View Answer
Answer: d
Explanation: The stripos() function finds the position of the first occurrence of a string inside another
string. In this case it returns 7.
12. Which of the following PHP functions can be used for generating unique ids?
a) md5()
b) uniqueid()
c) mdid()
d) id()
View Answer
Answer: b
Explanation: The function uniqueid() is used to generate a unique ID based on the microtime (current
time in microseconds). The ID generated from the function uniqueid() is not optimal, as it is based on the
system time. To generate an ID which is extremely difficult to predict we can use the md5() function.
<?php
class Example
public $name;
function Sample()
?>
a) function sample()
c) public $name;
d) class Example
View Answer
Answer: c
Explanation: Above code is an example of ‘classes’. Classes are the blueprints of objects. Classes are the
programmer-defined data type, which includes the local methods and the local variables. Class is a
collection of objects which has properties and behaviour.
echo $GREETING;
?>
a) $GREETING
b) no output
d) GREETING
View Answer
Answer: b
Explanation: Constants do not need a $ before them, they are referenced by their variable names itself.
15. A function in PHP which starts with __ (double underscore) is known as __________
a) Default Function
c) Inbuilt Function
d) Magic Function
View Answer
Answer: d
Explanation: PHP functions that start with a double underscore – a “__” – are called magic functions.
They are functions that are always defined inside classes, and are not stand-alone functions.
16. How many functions does PHP offer for searching and modifying strings using Perl-compatible regular
expressions.
a) 10
b) 7
c) 8
d) 9
View Answer
Answer: c
17. Which of the following web servers are required to run the PHP script?
b) IIS
c) XAMPP
View Answer
Answer: b
Explanation: To run PHP code you need to have PHP and a web server, both IIS, XAMPP and Apache are
web servers. You can choose either one according to your platform.
18. What will be the output of the following PHP code snippet?
<?php
$url = "[email protected]";
?>
b) [email protected]
c) phpmcq@
d) sanfoundry.com
View Answer
Answer: d
Explanation: The strstr() function returns the remainder of a string beginning with the first occurrence of
a predefined string.
19. Which of the following PHP functions can be used to get the current memory usage?
a) memory_get_usage()
b) memory_get_peak_usage()
c) get_peak_usage()
d) get_usage()
View Answer
Answer: a
Explanation: memory_get_usage() returns the amount of memory, in bytes, that’s currently being
allocated to the PHP script. We can set the parameter ‘real_usage’ to TRUE to get total memory allocated
from system, including unused pages. If it is not set or FALSE then only the used memory is reported. To
get the highest amount of memory used at any point, we can use the memory_get_peak_usage()
function.
20. Which one of the following PHP function is used to determine a file’s last access time?
a) filetime()
b) fileatime()
c) fileltime()
d) filectime()
View Answer
Answer: b
Explanation: The fileatime() function returns a file’s last access time in Unix timestamp format or FALSE
on error.
<?php
$x = 5;
$y = 10;
function fun()
$y = $GLOBALS['x'] + $GLOBALS['y'];
fun();
echo $y;
?>
a) 5
b) 10
c) 15
d) Error
View Answer
Answer: b
Explanation: The value of global variable y does not change therefore it’ll print 10;
a) function __construct()
b) function _construct()
c) classname()
d) _construct()
View Answer
Answer: a
Explanation: PHP recognizes constructors by double underscore followed by the construct keyword. Its
syntax is function __construct ([ argument1, argument2,…..]) { Class Initialization code }.
23. The developers of PHP deprecated the safe mode feature as of which PHP version?
a) PHP 5.3.1
b) PHP 5.3.0
c) PHP 5.1.0
d) PHP 5.2.0
View Answer
Answer: b
Explanation: This happened because safe mode often creates many problems as it resolves, largely due to
the need for enterprise applications to use many of the features safe mode disables.
24. What will be the value of the variable $input in the following PHP program?
<?php
$input = strip_tags($input,"<i></i>");
echo $input;
?>
View Answer
Answer: a
Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially wreak havoc
on a page.
25. Which of the following variables does PHP use to authenticate a user?
i) $_SERVER['PHP_AUTH_USER'].
ii) $_SERVER['PHP_AUTH_USERS'].
iii) $_SERVER['PHP_AUTH_PU'].
iv) $_SERVER['PHP_AUTH_PW'].
b) i) and iv)
d) i) and ii)
View Answer
Answer: b
View Answer
Answer: c
Explanation: PDO stands for PHP Data Object. The PDO class provides a common interface to different
database applications.
<?php
$a = 100;
printf("PHP Quiz");
printf("PHP MCQ");
printf("PHP Program");
?>
a)
PHP Quiz
PHP MCQ
PHP Program
b) PHP Quiz
c) No output
d) PHP MCQ
View Answer
Answer: b
i) for loop
a) Only iv)
b) i) and ii)
View Answer
Answer: d
Explanation: All are supported looping statements in PHP as they can repeat the same block of code a
given number of times, or until a certain condition is met.
a) echo “\$x”;
b) echo “$$x”;
c) echo “/$x”;
d) echo “$x;”;
View Answer
Answer: a
Explanation: A backslash is used so that the dollar sign is treated as a normal string character rather than
prompt PHP to treat $x as a variable. The backslash used in this manner is known as the escape character.
a) PHP 6
b) PHP 4
c) PHP 5
d) PHP 5.3
View Answer
Answer: c
<?php
$x = 4;
$y = 3
$z = 1;
$z = $z + $x + $y;
echo "$z";
?>
a) 15
b) 8
c) 1
d) $z
View Answer
Answer: b
Explanation: Normal addition of variables x, y and z occurs and result of 8 will be displayed.
<?php
$a = "$winner";
$b = "/$looser";
echo $a,$b;
?>
a) /
b) $looser
c) /$looser
d) $winner/$looser
View Answer
Answer: a
Explanation: Since variables $winner and $looser is not defined we only see / as output.
33. Which one of the following is the default PHP session name?
a) PHPSESSIONID
b) PHPIDSESS
c) PHPSESSID
d) PHPSESID
View Answer
Answer: c
Explanation: PHPSESSID is the default PHP session name. You can change this name by using the
session.name directive.
<?php
$mcq = 1;
switch(print $mcq)
case 2:
print "HTML";
break;
case 1:
print "CSS";
break;
default:
print "JavaScript";
?>
a) error
b) 1HTML
c) 1JavaScript
d) 1CSS
View Answer
Answer: d
<?php
define("VAR_NAME","test");
${VAR_NAME} = "value";
echo VAR_NAME;
echo ${VAR_NAME};
?>
a) testtest
b) testvalue
d) test
View Answer
Answer: b
36. Which PHP function displays the web page’s most recent modification date?
a) getlastmod()
b) get_last_mod()
c) lastmod()
d) last_mod()
View Answer
Answer: a
Explanation: The function getlastmod() gets the time of the last modification of the main script of
execution. It returns the value of the page’s last modified header or FALSE in the case of an error.
<?php
$i = 5;
print $i;
?>
a) 555555555…infinitely
b) 54321
c) error
d) 5
View Answer
Answer: a
function constant()
echo greeting;
?>
a) GREETING
b) Welcome to Sanfoundry
c) ERROR
d) greeting
View Answer
Answer: b
Explanation: By default, constants are case sensitive in php. But the third parameter in define(), if set to
true, makes constants case insensitive.
39. Which variable is used to collect form data sent with both the GET and POST methods?
a) $_BOTH
b) $REQUEST
c) $_REQUEST
d) $BOTH
View Answer
Answer: c
Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an HTML form.
40. What will be the output of the following PHP program?
<?php
echo pos($php);
?>
a) Function
b) File
c) Strings
d) Array
View Answer
Answer: d
Explanation: The pos() function returns the value of the current element in an array, and since no
operation has been done, the current element is the first element.
a) 1
b) 5
c) 12
d) Error
View Answer
Answer: b
Explanation: ?: is known as ternary operator. If condition is true then the part just after the ? is executed
else the part after
This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “HTML Forms”.
1. Which two predefined variables are used to retrieve information from forms?
View Answer
Answer: b
Explanation: The global variables $_GET is used to collect form data after submitting an HTML form with
the method=”get”. The variable $_SET is also used to retrieve information from forms.
2. The attack which involves the insertion of malicious code into a page frequented by other users is
known as _______________
c) cross-site scripting
d) scripting
View Answer
Answer: c
Explanation: The cross-site scripting attack is among one of the top five security attacks carried out across
the Internet. It is also known as XSS, this attack is a type of code injection attack which is made possible
by incorrectly validating user data, which usually gets inserted into the page through a web form or using
an altered hyperlink.
3. When you use the $_GET variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few
View Answer
Answer: c
Explanation: The information sent from a form with the method GET is visible to everyone i.e. all variable
names and values are displayed in the URL.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
4. When you use the $_POST variable to collect data, the data is visible to ___________
a) none
b) only you
c) everyone
d) selected few
View Answer
Answer: b
Explanation: The information sent from a form with the method POST is invisible to others i.e. all
names/values are embedded within the body of the HTTP request.
5. Which variable is used to collect form data sent with both the GET and POST methods?
a) $BOTH
b) $_BOTH
c) $REQUEST
d) $_REQUEST
View Answer
Answer: d
Explanation: In PHP the global variable $_REQUEST is used to collect data after submitting an HTML form.
6. Which one of the following should not be used while sending passwords or other sensitive
information?
a) GET
b) POST
c) REQUEST
d) NEXT
View Answer
Answer: a
Explanation: The information sent from a form with the method GET is visible to everyone i.e. all variable
names and values are displayed in the URL. So, it should not be used while sending passwords or other
sensitive information.
7. Which function is used to remove all HTML tags from a string passed to a form?
a) remove_tags()
b) strip_tags()
c) tags_strip()
d) tags_remove()
View Answer
Answer: b
Explanation: The function strip_tags() is used to strip a string from HTML, XML, and PHP tags.
8. What will be the value of the variable $input in the following PHP code?
<?php
$input = strip_tags($input,"<i></i>");
echo $input;
?>
View Answer
Answer: d
Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially wreak havoc
on a page.
a) FILTER_VALIDATE_EMAIL
b) FILTER_VALIDATE_MAIL
c) VALIDATE_EMAIL
d) VALIDATE_MAIL
View Answer
Answer: a
a) 5
b) 6
c) 7
d) 8
View Answer
Answer: c
« PrevNext »
This set of HTML Interview Questions and Answers focuses on “The Rules of (X)HTML”.
i. <B>Go boldly</B>
a) iv
b) i
d) both iv and i
View Answer
Answer: c
Explanation: Traditional HTML is case insensitive and thus we can write tag/element name either in
lowercase or uppercase or both which will be ignored by browser by default.
advertisement
a) True
b) False
View Answer
Answer: b
Explanation: Traditionally XHTML is case sensitive while HTML is case insensitive. In HTML these are
ignored by default by browsers.
<strong>T e s t o f s p a c e s</strong><br>
a) T e s t o f s p a c e s
Testofspaces
b) Testofspaces
Testofspaces
c) T e s t o f s p a c e s
Test of spaces
d) T e s t o f s p a c e s T e s t o f s p a c e s
View Answer
Answer: c
Explanation: The strong tag is used to highlight the importance of text/paragraph. <br> tag is used for a
line break in HTML. Ant white space between characters displays as a single space.
i.<ul>
</ul>
ii.<ul>
</ul>
a) i
b) ii
c) i and ii
d) Neither i nor ii
View Answer
Answer: b
Explanation: Content model specifies that certain elements are supposed to occur only within other
elements. The <ul> tag which is for unordered list should contain <li> tags which are for list specification.
The <p> tag is used for paragraph in HTML.
a) <hr/>
b) <br/>
c) <p/>
View Answer
Answer: c
Explanation: An element is said to be empty if it doesn’t contain any content in it. The <hr/> and <br/>
tag which is used for a horizontal line and line break respectively, doen’t contains any content in it and
thus are called empty elements in HTML. <p> tag contains text/paragraph in it so it’s not an empty
element.
a) True
b) False
View Answer
Answer: b
Explanation: As a block tag, <p> induces a return by default, but when used repeatedly, like
<p></p><p></p>, it does not have any effect on document.
a) i
b) ii
c) i and ii
d) Neither i nor ii
View Answer
Answer: b
Explanation: In markup, tags can be nested. The first tag who is going to nest other tag must end after
that nested tag which means if <i> tag is nested in <b> tag then <b> must be closed after closing of the
<i> tag.
View Answer
Answer: d
Explanation: Rules of XHTML are as- 1) XHTML elements must be properly nested
b) >
c) <
d) &st;
View Answer
Answer: d
Explanation: Character escapes in markup is to represent any Unicode character in HTML, XHTML or XML
using only ASCII characters. There are different types of escape character entity in HTML. Some of them
are > which is used for greater than(>) , > is basically a entity number which is used for greater than(>), <
stands for less than(<), etc. There doesn’t exist any &st escape character entity in markup.
<html>
<head>
</head>
<body>
<li>
<ul><p>Hello</p></ul>
</li>
<br>
<hr>
</body>
</html>
a) 2
b) 3
c) 1
d) 0
View Answer
Answer: b
Explanation: We can write <p></p> tag in <ul></ul> tag as there is no such rule or else limitation. The tags
<br> and <hr> are closed by default in browser.
« PrevNext »
This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Working with Forms &
Minification”.
1. Which of the following is not the form type for adding text?
a) Text input
b) Text area
c) Password input
d) Submit button
View Answer
Answer: d
Explanation: There are many types of form controls. Adding text, Submitting forms, Making choices and
Uploading files are some of them. For an adding text, we can use Text input, Text area, and Password
input. For making choices there are checkboxes, radio buttons, and drop-down boxes.
2. In the processing of information, the server does not use the language _____
a) C#
b) JAVA
c) C++
d) VB.net
View Answer
Answer: c
Explanation: When we enter a new value through form it goes to the server for processing information
and this information is processed using languages C#, PHP, JAVA or VB.net. The database can also store
the information.
3. For creating single line text box for searching queries, we use the type ___________
a) placeholder
b) search
c) url
d) hidden
View Answer
Answer: b
Explanation: For creating a single line text box for searching queries we use the type=”search”. In old
browsers, it will be simply a single line text box. Safari adds across that clear search box when we enter
new data to search. It also rounds the corners on search input fields by default.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
a) PHP
b) HTML
c) JavaScript
d) jQuery
View Answer
Answer: c
Explanation: Form validation is checking if the form has been filled correctly. Traditionally it has been
performed by JavaScript but now HTML5 is introducing validation. Hence browser does all the work of
validation. Validation reduces the amount of work for the server.
a) <legend>
b) <fieldset>
c) <label>
d) <select>
View Answer
Answer: b
Explanation: For grouping form controls together we use <fieldset> element. Fieldset is shown with a line
around edge. Appearance can be adjusted by CSS.
E.g. <fieldset> <legend> details </legend> <label> Name: <br/> <>input type=”text” name=”name”/>
</label> <br/> </fieldset>
a) JavaScript
b) CSS
c) HTML
d) PHP
View Answer
Answer: a
Explanation: Among the four languages JavaScript, PHP, HTML and CSS, JavaScript has the most potential
for minification. In JavaScript whitespaces and comments are removed. Windows-style line breaks (CRLF)
is converted to UNIX-style breaks (LF). Moreover, variable names can also be shortened.
a) HTML
b) C++
c) C
d) Java
View Answer
Answer: d
Explanation: YUI compressor is one of the best compressor. It is a command-line minifier which is written
in Java. It can process CSS as well as JavaScript. It is simple to run it like-
a) YUI
b) JSMin
c) Packer
d) Closure(advanced)
View Answer
Answer: a
Explanation: YUI compressor gives maximum GZIPPED compression i.e. 21 out of 122. JSMin gives 23 out
of 122, Closure(simple) gives 21 out of 122, Closure(advanced) gives 18 out of 122, Packer gives 23 out of
122. There is also redundancy due to GZIP compression.
9. CSSMin is written in ___________
a) C++
b) Java
c) PHP
d) C
View Answer
Answer: b
a) JavaScript
b) Java
c) C++
d) C
View Answer
Answer: a
Explanation: There are mainly two popular HTML minifier. HTMLMinifier and htmlcompressor first are
written in JavaScript. It is to be run via a web browser. Second is command-line Java application.
HTMLMinifier offers better levels of compression.
View Answer
Answer: d
Explanation: There are many options available in HTMLMinifier like it removes comments, also comments
from CSS and JavaScript blocks, collapses whitespace, removes character data blocks from JavaScript and
CSS, Collapses Boolean attributes, removes redundant attributes, uses a short doctype, removes empty
elements, removes attribute quotes
« PrevNext »
This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Working with Tables”.
a) <tr>
b) <td>
c) <th>
d) <thead>
View Answer
Answer: b
Explanation: td stands for table data, we can represent each cell of the table by using <td>, at the end we
used </td> tag. But some browsers by default draw the lines around table. <tr> is used to indicate start of
every row i.e. it stands for table row. The header information is present in <th> tag. <thead> tag contains
the group of header.
a) <td>
b) <tr>
c) <thead>
d) <th>
View Answer
Answer: d
Explanation: <th> element is used for representing heading of column or a row. It works same as <td>
element. If shell has no content we can use <th> element also there. We can use scope attribute for
specifying the heading is for row or column. Usually content of <th> is represented in bold. <thead> tag
contains the group of header. <tr> is used to indicate start of every row i.e. it stands for table row.
a) <thead>
b) <tfoot>
c) <th>
d) <tbody>
View Answer
Answer: a
Explanation: Headings of the table lies inside <thead> element. Footer lies inside the <tfoot> element.
The body of the table lies inside <tbody> element. <th> is used for giving heading to a row or a column.
Every element must have closing tag also i.e. </thead>, </tfoot>, </tbody>
advertisement
4. Which of the following is not the element associated with HTML table layout?
a) size
b) spanning
c) alignment
d) color
View Answer
Answer: d
Explanation: There are three elements in HTML table layout i.e. size, spanning and alignment. Layout type
can be achieved by setting Rows elements layout attribute to Fixed or Auto. Auto attribute relies on
browser compatibility whereas fixed layout relies on developer specification.
a) Row
b) <thead>
c) Column cell
d) Rows
View Answer
Answer: b
Explanation: Column cell, Row, and Rows are the container elements. They have a class attribute with the
help of this we can apply special styling. Table alignment is also controlled style sheet classes. Text-align
and vertical-align are the style attributes that align the content of the table.
a) <caption>
b) <thead>
c) <th>
d) <tr>
View Answer
Answer: a
Explanation: For adding caption to the table we use <caption> tag. It should be used just below the
<table> tag.
Syntax is
<table>
<tr><td>$12</td>$45<td></td> </tr>
</table>.
<thead> tag contains the group of header. <tr> is used to indicate start of every row i.e. it stands for table
row. The header information is present in <th> tag.
a) pixels
b) cm
c) mm
d) inch
View Answer
Answer: a
Explanation: border-spacing and border-collapse are the two properties by which one can set the border
and its styling in a table. We give its value in pixels.
table { border-collapse: collapse; border-spacing: 14px } th, td{ border: 12 px solid red; padding: 20px
13px; }
a) <th>
b) <td>
c) <tr>
d) <thead>
View Answer
Answer: c
Explanation: Borders can’t be applied on <tr> elements. It can’t be applied on table structural elements.
For setting borders with <tr> element, border-collapse property should be set to collapse.
Syntax is
a) width=multi-length[CN].
b) span=number[CN].
c) scope=scope-name[CN].
d) headers=idrefs[CS].
View Answer
Answer: b
Explanation: span=number[CN] attribute’s value must be an integer and greater than 0. It specifies the
number of columns in a group. When span attribute is not in use, colgroup defines a single column group
containing one column. width=multi-length[CN] specifies default width of for every column.
scope=scope-name[CN] specifies set of data cells for which going header cell gives header information.
The headers=idrefs[CN] provides list of header cells that gives header information.
a) Fixed
b) Percentage
c) Proportional
d) Pixels
View Answer
Answer: d
Explanation: We can specify column width in three ways i.e. Percentage, Fixed, Proportional. Fixed width
is given in pixels. Percentage specification is the percentage of horizontal space availability in the table.
The proportional specification is the portions of fixed horizontal space required for the table.
a) row
b) rowgroup
c) col
d) <head>
View Answer
Answer: d
Explanation: scope attribute defines a set of data cell. It is used in place of headers. This attribute can
have one of the value among rowgroup, row, colgroup, col, rowgroup, and colgroup provides information
of header cell of the corresponding row and column groups.
12. Which of the following is not the value for frame attribute?
a) above
b) void
c) none
d) box
View Answer
Answer: c
Explanation: Frame attribute gives information about which sides of the frame surrounding that table will
be visible. The values that this attribute can take are lhs, rhs, box, border, vsides, hsides, below, above,
void.
13. Which of the following is not the value for rules attribute?
a) vsides
b) rows
c) all
d) groups
View Answer
Answer: a
Explanation: The rules which will appear between cells of the table is specified by this attribute. It can
take the values groups, none, rows, all and cols. None is the default value, rows are for appearance
between rows only and cols is for columns only.
14. Which of the following is not the value for align attribute?
a) justify
b) char
c) middle
d) left
View Answer
Answer: c
Explanation: align attribute is the alignment of data and for justification of text in the cell. It can take the
values left, right, justify, center, char. Justify is for double justifying the text, char is for aligning text
around a particular character.
b) middle
c) baseline
d) bottom
View Answer
Answer: a
Explanation: valign attribute is for specifying the vertical position of the data in a cell. It can take the
values middle, top, baseline, bottom, Top is for the top of the cell’s data, middle is for the centered data,
bottom is for the bottom of the cell, first text line occurs on the baseline which is common to all the cells.
« PrevNext »
This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “HTML5 Layout Elements”.
a) <footer>
b) <header>
c) <head>
d) <body>
View Answer
Answer: a
Explanation: Footer for its nearest sectioning content or sectioning root element is represented by
<footer> element. It typically contains information about author of the section, links to related
documents or copyright data. An introductory content lies in <header>. <head> is container for all head
elements. A document’s body is defined by <body> tag.
b) <address>
c) heading elements
d) authorship information
View Answer
Answer: b
Explanation: <header> element contains one or more than one heading elements, authorship
information, logo or icon. <header> tag can’t be placed inside <address> or <footer> or inside another
<header> element.
a) <nav>
b) <address>
c) <footer>
d) <header>
View Answer
Answer: a
Explanation: The major navigational blocks on site like primary site navigation is contained by <nav>
element.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
E.g.
<nav>
<ul>
</ul>
</nav>
Footer typically contains information about author of the section, links to related documents or copyright
data. An introductory content lies in <header>. Contact information of author/owner of a document can
be provided by <address> tag.
a) <nav>
b) <header>
c) <footer>
d) <article>
View Answer
Answer: d
a) <aside>
b) <article>
c) <address>
d) <footer>
View Answer
Answer: a
Explanation: <aside> element can be used inside <article> or outside it also. When it is used inside
<aticle> it contains information that is related to article. When <aside> is used outside <article>, it acts as
container for content that is related to the whole page. Contact information of author/owner of a
document can be provided by <address> tag. Footer typically contains information about author of the
section, links to related documents or copyright data.
a) <aside>
b) <footer>
c) <section>
d) <div>
View Answer
Answer: c
Explanation: Grouping of related content together is done by <section> element. Each section will have
its own heading. This element should not be used as wrapper for entire page. If we wish of containing a
element for entire page, this will be best done by <div> element. Footer typically contains information
about author of the section, links to related documents or copyright data. <aside> is a container of
contetnt related to it’s surrounding. For grouping together related elements we use <div> element.
7. For grouping together one or more <h1> to <h6> element what element is used?
a) <header>
b) <hgroup>
c) <div>
d) <section>
View Answer
Answer: b
Explanation: For grouping together set of one or more <h1> to <h6> element we use <hgroup> element.
We can group together the primary heading and the subheading. E.g. <hgroup> <h2> Winter is coming!
</h2> <h3>Its too cold</h3> </hgroup>. Grouping of related content together is done by <section>
element. For grouping together related elements we use <div> element. An introductory content lies in
<header>.
a) <div>
b) <hgroup>
c) <section>
d) <header>
View Answer
Answer: a
Explanation: For grouping together related elements we use <div> element. Anything that lies outside of
<footer>, <aside> or <content> elements can be considered as main content. E.g. <div class= “wrap”>
<header> <h1> kitchen </h1> </div>. Grouping of related content together is done by <section> element.
An introductory content lies in <header>. For grouping together set of one or more <h1> to <h6> element
we use <hgroup> element
« PrevNext »
This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Embedding JavaScript in
HTML”.
1. Which of the following is a way of embedding Client-side JavaScript code within HTML documents?
a) From javascript:encoding
View Answer
Answer: b
Explanation: The Client-side JavaScript code is embedded within HTML documents in four ways :
View Answer
Answer: a
Explanation: JavaScript code can appear inline within an HTML file between the “script” tags. Javascript
can also be included from an external file specified by the src attribute of a “script” tag.
a) !
b) >
c) &
d) .
View Answer
Answer: c
Explanation: If your JavaScript code contains the < or & characters, these characters are interpreted as
XML markup. Element tags must begin with the < character, and entities and character references in an
XML document must begin with the & character.
advertisement
a) HTML
b) HEAD
c) SCRIPT
d) BODY
View Answer
Answer: a
Explanation: The “html” tag is the root element of any HTML document regardless of it containing a
JavaScript code or not. Body tag includes the main content that is shown on the website.
View Answer
Answer: b
Explanation: Date() is a predefined function in javascript which returns the date in string form. The above
code determines the current time and stores it in the variable “now”.
6. What is the code to start displaying the time when the document loads?
a) onload = displayTime;
b) window. = displayTime;
c) window.onload = displayTime;
d) window.onload = start;
View Answer
Answer: c
Explanation: window.onload is used to access the screen while the page is loading. The above code starts
displaying the time when the document loads.
a) It becomes self-cached
View Answer
Answer: d
Explanation: The main advantage of using the src attribute is that it simplifies your HTML files by allowing
you to remove large blocks of JavaScript code from them. Hence separate files for css and javascript files
are made to make the code modular and readable.
8. What will be done if more than one page requires a file of JavaScript code?
c) Must be re executed
View Answer
Answer: b
Explanation: If a file of JavaScript code is shared by more than one page, it only needs to be downloaded
once, by the first page that uses it—subsequent pages can retrieve it from the browser cache. This makes
the loading process easier and hence faster.
a) text/css
b) text/javascript
c) html
d) xml
View Answer
Answer: b
Explanation: The default value of the type attribute is “text/javascript”. You can specify this type explicitly
if you want, but it is never necessary.
c) No longer in use
View Answer
Answer: c
Explanation: The language attribute specifies the natural language of the content of a web page. The
language attribute is deprecated and should no longer be used.
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = numbers2;
return value * 2;
</script>
a) 8 9
b) 8 18
c) 4 9
d) Error
View Answer
Answer: b
Explanation: Map function creates a new array by performing a function on each array element.
myFunction multiplies each value with 2.
<script>
document.getElementById("demo").innerHTML = sum;
</script>
a) 100
b) 99
c) 0
d) error
View Answer
Answer: b
Explanation: Reduce function reduces the array values to a single variable. The function returns the sum
of array elements.
<p id="demo"></p>
<script>
</script>
a) true
b) false
c) 0
d) error
View Answer
Answer: b
Explanation: The every() method checks if all array values pass a test. The function tests if all the values
are greater than 18 or not.
<p id="demo"></p>
<script>
</script>
a) True
b) False
c) Error
d) Undefined
View Answer
Answer: a
Explanation: The some() method checks if some array values pass a test. Since some of the values are
greater than 10 the answer will be true.
<p id="demo"></p>
<script>
var a = arr.lastIndexOf("1");
document.getElementById("demo").innerHTML = (a + 1);
</script>
a) 2
b) 3
c) 4
d) 0
View Answer
Answer: c
Explanation: The lastindexof method returns the last occurrence of element in the array. The last
occurrence of 1 is at index 4.