0% found this document useful (0 votes)
75 views95 pages

Exam Software

R

Uploaded by

abdiaberagemechu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views95 pages

Exam Software

R

Uploaded by

abdiaberagemechu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 95

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?

a) Delete the previous session

b) Start a new session

c) Check whether a valid session exists

d) Handle the session

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.

2. How many ways can a session data be stored?

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).

3. Which directive determines how the session information will be stored?

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

4. Which one of the following is the default PHP session name?

a) PHPSESSID

b) PHPSESID

c) PHPSESSIONID

d) PHPIDSESS

View Answer

Answer: a

Explanation: You can change this name by using the session.name directive.

5. If session.use_cookie is set to 0, this results in use of _____________

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.

Check this: MCA Books | PHP Books

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

Explanation: The directive which determines this is session.cache_expire.

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.

10. Which one of the following function is used to start a session?

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().

2. What will the function session_id() return is no parameter is passed?

a) Current Session Identification Number

b) Previous Session Identification Number

c) Last Session Identification Number


d) Error

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.

Note: Join free Sanfoundry classes at Telegram or Youtube

advertisement

4. What will be the output of the following PHP code? (Say your previous session username was nachi.)

unset($_SESSION['username']);

printf("Username now set to: %s", $_SESSION['username']);

a) Username now set to: nachi

b) Username now set to: System

c) Username now set to:

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.

Take PHP Programming Tests Now!

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.

7. Which function effectively deletes all sessions that have expired?

a) session_delete()

b) session_destroy()

c) session_garbage_collect()

d) SessionHandler::gc

View Answer

Answer: d

Explanation: SessionHandler::gc is used to clean up expired sessions. It is called randomly by PHP


internally when a session_start() is invoked.

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.

9. The session_start() function must appear _________

a) after the html tag


b) after the body tag

c) before the body tag

d) before the html tag

View Answer

Answer: d

Explanation: Like this: <?php session_start(); ?> <html>

10. What is the return type of session_set_save_handler() function?

a) boolean

b) integer

c) float

d) character

View Answer

Answer: a

Explanation: Returns TRUE on success or FALSE on failure.

Questions & Answers (MCQs) focuses on “Uploading Files with PHP”.

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.

3. What is the default value of max_input_time directive?

a) 30 seconds

b) 60 seconds

c) 120 seconds

d) 1 second

View Answer

Answer: b

Explanation: The default value of the max_input_time directive is 60 seconds.

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.

5. What is the default value of the directive max_file_limit?

a) 10 files

b) 15 files

c) 20 files

d) 25 files

View Answer

Check this: MCA Books | Programming MCQs

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

Explanation: Its default value is 16M.

7. If you want to temporarily store uploaded files in the /tmp/phpuploads/ directory, which one of the
following statement will you use?

a) upload_tmp_dir “/tmp/phpuploads/ directory”

b) upload_dir “/tmp/phpuploads/ directory”

c) upload_temp_dir “/tmp/phpuploads/ directory”

d) upload_temp_director “/tmp/phpuploads/ directory”

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.

9. How many items are available in the $_FILES array?

a) 2
b) 3

c) 4

d) 5

View Answer

Answer: d

Explanation: $_FILEs[‘userfile’][‘error’], $_FILEs[‘userfile’][‘name’], $_FILEs[‘userfile’][‘size’],


$_FILEs[‘userfile’][‘tmp_name’], $_FILEs[‘userfile’][‘type’] are the five items in the array.

10. Which function is used to determine whether a file was uploaded?

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).

PHP Multiple Choice Questions – Session Handling

« 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?

a) Delete the previous session


b) Start a new session

c) Check whether a valid session exists

d) Handle the session

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.

2. How many ways can a session data be stored?

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).

3. Which directive determines how the session information will be stored?

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

4. Which one of the following is the default PHP session name?

a) PHPSESSID

b) PHPSESID

c) PHPSESSIONID

d) PHPIDSESS

View Answer

Answer: a

Explanation: You can change this name by using the session.name directive.

5. If session.use_cookie is set to 0, this results in use of _____________

a) Session

b) Cookie

c) URL rewriting

d) Nothing happens

View Answer

Check this: MCA Books | PHP Books

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

Explanation: The directive which determines this is session.cache_expire.


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.

10. Which one of the following function is used to start a session?

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.

PHP Multiple Choice Questions – Functions

« PrevNext »

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses on “Functions”.

1. How to define a function in PHP?

a) function {function body}


b) data type functionName(parameters) {function body}

c) functionName(parameters) {function body}

d) function functionName(parameters) {function body}

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.

2. Type Hinting was introduced in which version of PHP?

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?

Note: Join free Sanfoundry classes at Telegram or Youtube

advertisement

<?php

function calc($price, $tax)

{
$total = $price + $tax;

$pricetag = 15;

$taxtag = 3;

calc($pricetag, $taxtag);

?>

a) Call By Value

b) Call By Reference

c) Default Argument Value

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.

Take PHP Programming Tests Now!

4. What will be the output of the following PHP code?

<?php

function calc($price, $tax="")

$total = $price + ($price * $tax);

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.

5. Which of the following are valid function names?

i) function()

ii) €()

iii) .function()

iv) $function()

a) Only i)

b) Only ii)

c) i) and ii)

d) iii) and iv)

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()

echo 'I am b';

echo 'I am a';

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.

7. What will be the output of the following PHP code?


<?php

function a()

function b()

echo 'I am b';

echo 'I am a';

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();

8. What will be the output of the following PHP code?

<?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.

9. A function in PHP which starts with __ (double underscore) is known as __________

a) Magic Function

b) Inbuilt Function

c) Default Function

d) User Defined 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";

$var1("will this work");

?>

a) Error

b) $msg

c) 0

d) Will this work

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

JavaScript Questions & Answers – JavaScript in Web Browsers – II

« PrevNext »
This set of JavaScript Interview Questions and Answers focuses on “JavaScript in Web Browsers – II”.

1. What is the property to access the first child of a node?

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?

a) style and font

b) style and className

c) size and style

d) className and font

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).

3. Which of the following object belongs to the style property?

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.

Subscribe Now: JavaScript Newsletter | Important Subjects Newsletters

advertisement

4. What is the purpose of the event handlers in the JavaScript?

a) Adds innerHTML page to the code

b) Performs handling of exceptions and occurrences

c) Allows JavaScript code to alter the behaviour of windows

d) Change the server location

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.

Get Free Certificate of Merit in JavaScript Now!

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”?

a) var elements = document.getElementsByClassName(“reveal”);

b) var elements = document.getElementByClassName(“reveal”);

c) var elements = document.getElementByName(“reveal”);

d) var elements = document.getElementsClassName(“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?

a) timestamp.onLoad = function() { this.innerHTML = new Date().toString(); }

b) timestamp.onclick = function() { this.innerHTML = new Date().toString(); }

c) timestamp.onload = function() { this.innerHTML = new Date().toString(); }

d) timestamp.onclick = function() { innerHTML = new Date().toString(); }

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.

9. Which of the following is not an object?

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.

JavaScript Questions & Answers – Client-Side JavaScript

« PrevNext »

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Client-Side JavaScript”.

1. The main purpose of JavaScript in web browser is to ___________

a) Creating animations and other visual effects

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.

3. The behaviour of the document elements can be defined by __________

a) Using document object

b) Registering appropriate event handlers

c) Using element object

d) Using data 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.

Note: Join free Sanfoundry classes at Telegram or Youtube

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.

5. The HTML5 specification does not includes __________

a) Data storage

b) Graphics APIs

c) Other APIs for web apps

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.

Take JavaScript Tests Now!

6. Which of the following is not an advanced services?

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.

7. JavaScript code between a pair of “script” tags are called __________

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.

8. Client-side JavaScript code is embedded within HTML documents in __________

a) A URL that uses the special javascript:encoding

b) A URL that uses the special javascript:stack

c) A URL that uses the special javascript:protocol

d) A URL that uses the special javascript:code

View Answer

Answer: c

Explanation: The Client-side JavaScript code is embedded within HTML documents in four ways :

Inline, between a pair of “script” tags

From an external file specified by the src attribute of a “script” tag

In an HTML event handler attribute, such as onclick or onmouseover

In a URL that uses the special javascript: protocol.


9. What is the programming philosophy that argues that content and behaviour should as much as
possible be kept separate?

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?

a) Static Web Pages

b) Interactive Web Pages

c) Conditional Web Pages

d) All web pages

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.

JavaScript Questions & Answers – Client-Side Databases

« PrevNext »

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Client-Side Databases”.
1. The Client-Side Databases are stored in the ____________

a) The JavaScript code

b) User’s computer

c) Both JavaScript code and 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.

2. Which of the following use the Web SQL Database?

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?

a) Web SQL 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

4. In the IndexedDB database, database is defined as _____________

a) A collection of objects

b) A collection of named object stores

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.

5. A key path is defined as ______________

a) A url that directs to the value

b) A value that is similar to hash table

c) A value that tells the database how to extract an object’s key from the object

d) A url that redirects

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.

Check this: Programming Books | Information Science MCQs

6. How does IndexedDB provide atomicity?

a) Grouping among the data

b) Grouping within a transaction

c) Grouping the data

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.

7. Which of the following is a feature of the IndexedDB API?

a) Simplifies the transaction management

b) Need not manage the transaction at all

c) Enhances the storage

d) Creates a link between data

View Answer

Answer: a

Explanation: One of the convenient feature of the IndexedDB API is that it simplifies the transaction
management.

8. What is the alternate way to search in an IndexedDB API?

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.

9. Which is the function used to look up an object?

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

PHP MCQ (Multiple Choice Questions)

Here are 1000 MCQs on PHP (Chapterwise).

1. What is PHP?

a) PHP is an open-source programming language

b) PHP is used to develop dynamic and interactive websites

c) PHP is a server-side scripting language

d) All of the mentioned

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.

2. Who is the father of PHP?

a) Drek Kolkevi

b) Rasmus Lerdorf

c) Willam Makepiece

d) List Barely

View Answer

Answer: b

Explanation: PHP was originally created by Rasmus Lerdorf in 1994.

3. What does PHP stand for?


a) PHP stands for Preprocessor Home Page

b) PHP stands for Pretext Hypertext Processor

c) PHP stands for Hypertext Preprocessor

d) PHP stands for Personal Hyper Processor

View Answer

Answer: c

Explanation: PHP previously stood for Personal Home Page now stands for “Hypertext Preprocessor”.

4. Which of the following is the correct syntax to write a PHP code?

a) <?php ?>

b) < php >

c) < ? 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) /* */

d) All of the mentioned

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

6. Which of the following is the default file extension of PHP files?

a) .php

b) .ph

c) .xml

d) .html

View Answer

Answer: a

Explanation: To run a PHP file on the server, it should be saved as AnyName.php

7. How to define a function in PHP?

a) functionName(parameters) {function body}

b) function {function body}

c) function functionName(parameters) {function body}

d) data type functionName(parameters) {function body}

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.

8. What will be the output of the following PHP code?

<?php
$x = 10;

$y = 20;

if ($x > $y && 1||1)

print "1000 PHP MCQ" ;

else

print "Welcome to Sanfoundry";

?>

a) no output

b) Welcome to Sanfoundry

c) 1000 PHP MCQ

d) error

View Answer

Answer: c

Explanation: Expression evaluates to true.

Output:

1000 PHP MCQ

9. Which is the right way of declaring a variable in PHP?

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.

10. What will be the output of the following PHP program?

<?php

$fruits = array ("apple", "orange", array ("pear", "mango"),"banana");

echo (count($fruits, 1));

?>

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.

11. What will be the output of the following PHP program?

<?php

function multi($num)

if ($num == 3)

echo "I Wonder";

if ($num == 7)

echo "Which One";


if ($num == 8)

echo "Is The";

if ($num == 19)

echo "Correct Answer";

$can = stripos("I love php, I love php too!","PHP");

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.

13. In the following PHP program, what is/are the properties?

<?php

class Example

public $name;

function Sample()

echo "Learn PHP @ Sanfoundry";

?>

a) function sample()

b) echo “This is an example”;

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.

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


<?php

define("GREETING", "PHP is a scripting language");

echo $GREETING;

?>

a) $GREETING

b) no output

c) PHP is a scripting language

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

b) User Defined 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

Explanation: The functions are preg_filter(), preg_grep(), preg_match(), preg_match_all(), preg_quote(),


preg_replace(), preg_replace_callback(), and preg_split().

17. Which of the following web servers are required to run the PHP script?

a) Apache and PHP

b) IIS

c) XAMPP

d) Any of the mentioned

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]";

echo ltrim(strstr($url, "@"),"@");

?>

a) [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.

21. What will be the output of the following PHP code?

<?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;

22. PHP recognizes constructors by the name _________

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 = "PHP<td>stands for</td>Hypertext<i>Preprocessor</i>!";

$input = strip_tags($input,"<i></i>");

echo $input;

?>

a) PHP stands for Hypertext <i>Preprocessor</i>!


b) PHP stands for Hypertext Preprocessor!

c) PHP <td>stands for</td> Hypertext <i>Preprocessor</i>!

d) PHP <td>stands for</td> Hypertext Preprocessor!

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'].

a) ii) and iv)

b) i) and iv)

c) ii) and iii)

d) i) and ii)

View Answer

Answer: b

Explanation: $_SERVER[‘PHP_AUTH_USER’] and $_SERVER[‘PHP_AUTH_PW’] store the username and


password values, respectively.

26. What does PDO stand for?

a) PHP Database Orientation

b) PHP Data Orientation


c) PHP Data Object

d) PHP Database Object

View Answer

Answer: c

Explanation: PDO stands for PHP Data Object. The PDO class provides a common interface to different
database applications.

27. What will be the output of the following PHP program?

<?php

$a = 100;

if ($a > 10)

printf("PHP Quiz");

else if ($a > 20)

printf("PHP MCQ");

else if($a > 30)

printf("PHP Program");

?>

a)

PHP Quiz

PHP MCQ

PHP Program

b) PHP Quiz

c) No output
d) PHP MCQ

View Answer

Answer: b

Explanation: In if else if one condition is satisfied then no other condition is checked.

28. Which of the looping statements is/are supported by PHP?

i) for loop

ii) while loop

iii) do-while loop

iv) foreach loop

a) Only iv)

b) i) and ii)

c) i), ii) and iii)

d) i), ii), iii) and iv)

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.

29. Which PHP statement will give output as $x on the screen?

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.

30. Which version of PHP introduced the advanced concepts of OOP?

a) PHP 6

b) PHP 4

c) PHP 5

d) PHP 5.3

View Answer

Answer: c

Explanation: Advanced concepts of OOP were introduced in PHP version 5.

31. What will be the output of the following PHP code?

<?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.

32. What will be the output of the following PHP program?

<?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.

34. What will be the output of the following PHP program?

<?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

Explanation: Print returns 1, thus it gives case 1.

35. What will be the output of the following PHP program?

<?php

define("VAR_NAME","test");

${VAR_NAME} = "value";

echo VAR_NAME;

echo ${VAR_NAME};

?>

a) testtest

b) testvalue

c) error, constant value cannot be changed

d) test

View Answer

Answer: b

Explanation: ${VAR_NAME} creates a new variable that is not same as VAR_NAME.

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.

37. What will be the output of the following PHP program?

<?php

$i = 5;

while (--$i > 0 && ++$i)

print $i;

?>

a) 555555555…infinitely

b) 54321

c) error

d) 5

View Answer

Answer: a

Explanation: As it is && operator it is being incremented and decremented continuously in PHP.

38. What will be the output of the following PHP code?


<?php

function constant()

define("GREETING", "Welcome to Sanfoundry",true);

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

$php = array("Array", "Function", "Strings", "File");

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.

41. If $a = 12 what will be returned when ($a == 12) ? 5 : 1 is executed?

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

PHP Questions & Answers – HTML Forms


« PrevNext »

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?

a) $GET & $SET

b) $_GET & $_SET

c) $__GET & $__SET

d) GET & SET

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 _______________

a) basic sql injection

b) advanced sql injection

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.

Check this: MCA Books | Programming MCQs

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 = "Swapna<td>Lawrence</td>you are really<i>pretty</i>!";

$input = strip_tags($input,"<i></i>");

echo $input;

?>

a) Swapna Lawrence you are really pretty!

b) Swapna <td>Lawrence</td> you are really<i>pretty</i>!

c) Swapna <td>Lawrence</td> you are really pretty!

d) Swapna Lawrence you are really<i>pretty</i>!

View Answer

Answer: d

Explanation: Italic tags <i></i> might be allowable, but table tags <td></td> could potentially wreak havoc
on a page.

9. To validate an email address, which flag is to be passed to the function filter_var()?

a) FILTER_VALIDATE_EMAIL

b) FILTER_VALIDATE_MAIL

c) VALIDATE_EMAIL

d) VALIDATE_MAIL

View Answer

Answer: a

Explanation: The FILTER_VALIDATE_EMAIL is used to validates an e-mail address.


10. How many validation filters like FILTER_VALIDATE_EMAIL are currently available?

a) 5

b) 6

c) 7

d) 8

View Answer

Answer: c

Explanation: There are seven validation filters. They are FILTER_VALIDATE_EMAIL,


FILTER_VALIDATE_BOOLEAN, FILTER_VALIDATE_FLOAT, FILTER_VALIDATE_INT, FILTER_VALIDATE_IP,
FILTER_VALIDATE_REGEXP, FILTER_VALIDATE_URL.

HTML Questions & Answers – The Rules of (X)HTML

« PrevNext »

This set of HTML Interview Questions and Answers focuses on “The Rules of (X)HTML”.

1. Which of the following prints bold letters in traditional HTML?

i. <B>Go boldly</B>

ii. <B>Go boldly</b>

iii. <b>Go boldly</B>

iv. <b>Go boldly</b>

a) iv

b) i

c) i, ii, iii, and iv

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.

Subscribe Now: HTML Newsletter | Important Subjects Newsletters

advertisement

2. XHTML is case insensitive and HTML is case sensitive.

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.

3. What output do you expect if the following markup is rendered?

Check this: Information Science MCQs | HTML Books

<strong>T e s t o f s p a c e s</strong><br>

<strong>T e s t &nbsp;o f&nbsp; 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.

4. Which of the following options follows content model in HTML?

i.<ul>

<p>Option one </p>

</ul>

ii.<ul>

<li>Option two </li>

</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.

5. Which of the following is not an empty element?

a) <hr/>
b) <br/>

c) <p/>

d) Both <hr/> and <br/>

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.

6. State true or false.

<p></p><p></p><p></p>produces numerous blank lines.

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.

7. Which of the following markup is correct?

i. <b><i>is in error as tags cross</b></i>

ii. <b><i>is not since tags nest</i></b>

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.

8. Which of the following is not a correct (X)HTML rule?

a) Attributes should be quoted

b) Tags should not nest tag

c) Attribute minimization is forbidden

d) Unknown attributes are not ignored by the browser

View Answer

Answer: d

Explanation: Rules of XHTML are as- 1) XHTML elements must be properly nested

2) XHTML elements must always be closed

3) XHTML elements must be in lowercase

4) XHTML documents must have one root element

5) Attribute names must be in lower case

6) Attribute values must be quoted

7) Attribute minimization is forbidden

9. Choose the incorrect escape character entity.


a) &gt;

b) &#62;

c) &lt;

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.

10. Identify the count of mistakes in the following 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.

HTML Questions & Answers – Working with Forms & Minification

« 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

4. Form validation traditionally was performed by ___________

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.

5. For grouping form controls we can use ___________

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.

Check this: Computer Science Books | Computer Science MCQs

E.g. <fieldset> <legend> details </legend> <label> Name: <br/> <>input type=”text” name=”name”/>
</label> <br/> </fieldset>

6. Which one has the most potential for minification?

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.

7. YUI compressor is written in ____________

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-

$java –jar /usr/local/bin//yuicompressor-2.3.5/build/yuicompressor-2.3.5.jar input.js > output.js

8. Which compressor gives maximum GZIPPED compression?

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

Explanation: CSSMin is written in Java. It preforms conversion of lowercase, ordering of properties,


replacement of names with numeric or hex equivalents. E.g. font-weight:bold can be written as font-
weight: 600, color: black to color: #000.

10. HTMLMinifier is written in ________

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.

11. Which option is not available in HTMLMinifier?

a) remove attribute quotes

b) use the short doctype

c) remove empty elements


d) replace <strong> with <b>

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

HTML Questions & Answers – Working with Tables

« PrevNext »

This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Working with Tables”.

1. Each cell of the table can be represented by using __________

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.

2. For heading we can use ____________

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.

3. Headings of table lies inside ___________

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>

Note: Join free Sanfoundry classes at Telegram or Youtube

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.

5. Which of the following element is not associated with a class attribute?

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.

Check this: HTML Books | Information Science MCQs

6. For adding caption to the table we use ____________

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>

<caption> Savings </caption>

<tr> <th> saving </th><th>loss</th> </tr>

<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.

7. border-spacing is given in _____________

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; }

8. Borders can’t be applied on ________________

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

table {border-collapse: collapse;}

th, td{border-bottom: 2px dotted red; }

tfoot tr:last-child td{border-bottom: 9 px;}

9. Which attribute defines numbers of columns in a group?

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.

10. Which of the following does not specify a column width?

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.

11. Scope attribute can’t have the value __________

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.

15. valign attribute does not take the value __________________


a) justify

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.

HTML Questions & Answers – HTML5 Layout Elements

« PrevNext »

This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “HTML5 Layout Elements”.

1. Which one of the following contains information about the author?

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.

2. Header element does not contain ___________


a) logo

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.

3. Which element contains major navigational block?

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>

<li><a href="https://www.sanfoundry.com/" class= “dream”>HTML</a> </li>


<li><a href="https://www.sanfoundry.com/">CSS</a> </li>

<li><a href="https://www.sanfoundry.com/">PHP</a> </li>

</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.

Check this: HTML Books | Computer Science Books

4. Which element represents self-contained composition in document?

a) <nav>

b) <header>

c) <footer>

d) <article>

View Answer

Answer: d

Explanation: A self-contained composition in document, application, page or site that is intended to be


independently distributable is represented by <article> element. Some of the examples are a magazine or
newspaper article or a forum post, or a blog entry. <nav> element contains all the nevigation links. Footer
typically contains information about author of the section, links to related documents or copyright data.
An introductory content lies in <header>.

5. Which of the following element is used as a container for content?

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.

6. Which element groups related content together?

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>.

8. Which element is used for grouping together related elements?

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

JavaScript Questions & Answers – Embedding JavaScript in HTML

« 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

b) External file specified by the src attribute of a “script” tag

c) By using a header tag


d) By using body tag

View Answer

Answer: b

Explanation: The Client-side JavaScript code is embedded within HTML documents in four ways :

Inline, between a pair of “script” tags

From an external file specified by the src attribute of a “script” tag

In an HTML event handler attribute, such as onclick or onmouseover

In a URL that uses the special javascript: protocol.

2. When does JavaScript code appear inline within an HTML file?

a) Between the “script” tag

b) Outside the “script” tag

c) Between or Outside the “script” tag

d) Between the header tag

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.

3. Which character in JavaScript code will be interpreted as XML markup?

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.

Subscribe Now: JavaScript Newsletter | Important Subjects Newsletters

advertisement

4. Which is the root element in a HTML document?

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.

5. What is the code for getting the current time?

a) now = new Date();

b) var now = new Date();

c) var now = Date();

d) var now = new Date(current);

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”.

Get Free Certificate of Merit in JavaScript 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.

7. One of the main advantage of using src attribute is ____________

a) It becomes self-cached

b) It makes the HTML file modular

c) It restricts manipulation in the HTML file

d) It simplifies the HTML files

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?

a) Downloads that many times


b) Retrives from the browser cache

c) Must be re executed

d) Must be included in all the pages

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.

9. What is the default value of the type attribute?

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.

10. The language is commonly used to __________________

a) Specify the user’s language

b) Specify the language going to be scripted

c) No longer in use

d) Specify the programmer’s favourable language

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.

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

<p id="demo"></p>

<script>

var numbers1 = [4, 9];

var numbers2 = numbers1.map(myFunction);

document.getElementById("demo").innerHTML = numbers2;

function myFunction(value, index, array)

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.

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


<p id="demo"></p>

<script>

var numbers = [45, 4, 9, 16, 25];

var ans = numbers.reduce(myFunction);

document.getElementById("demo").innerHTML = sum;

function myFunction(total, value, index, array)

return total + value;

</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.

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

<p id="demo"></p>

<script>

var numbers = [45, 4, 9, 16, 25];

var arr= numbers.every(myFunction);


document.getElementById("demo").innerHTML =arr;

function myFunction(value, index, array)

return value > 18;

</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.

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

<p id="demo"></p>

<script>

var numbers = [45, 4, 9, 16, 25];

var someOver18 = numbers.some(myFunction);

document.getElementById("demo").innerHTML = "Some over 18 is " + someOver18;

function myFunction(value, index, array)

return value > 10;


}

</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.

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

<p id="demo"></p>

<script>

var arr = ["1", "1", "2", "1"];

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.

You might also like