Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
31 views

Big-d Internet Programming

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Big-d Internet Programming

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

INTERNET PROGRAMING

1. What is HTML?
a) HTML describes the structure of a webpage
b) HTML is the standard markup language mainly used to create web pages
c) HTML consists of a set of elements that helps the browser how to view the content
d) All of the mentioned
View Answer
Answer: d
Explanation: HTML is the standard markup language mainly used to create web pages.
HTML describes the structure and layout of a webpage. HTML consists of a series of
elements that helps the browser how to display content easily.
2. Who is the father of HTML?
a) Rasmus Lerdorf
b) Tim Berners-Lee
c) Brendan Eich
d) Sergey Brin
View Answer
Answer: b
Explanation: Timothy John Berners-Lee (TimBL) is known as the father of HTML. He is a
British computer scientist, best known as the inventor of the World Wide Web.
3. HTML stands for __________
a) HyperText Markup Language
b) HyperText Machine Language
c) HyperText Marking Language
d) HighText Marking Language
View Answer
Answer: a
Explanation: HTML stands for “HyperText Markup Language”. HTML is the standard
markup language mainly used to design and create web pages and web applications.
4. What is the correct syntax of doctype in HTML5?
a) </doctype html>
b) <doctype html>
c) <doctype html!>
d) <!doctype html>
View Answer
Answer: d
Explanation: The correct syntax of HTML5 doctype is <!doctype html>, doctype is the
very first thing to write in HTML5. <!doctype html> or <!DOCTYPE HTML> both are
same because ‘doctype’ keyword is not case sensitive.
5. Which of the following is used to read an HTML page and render it?
a) Web server
b) Web network
c) Web browser
d) Web matrix
View Answer
Answer: c
Explanation: A web browser (commonly referred to as a browser) is a software
application for retrieving, presenting and traversing information resources on the World
Wide Web. A web server process, store and display output to the client as per their
request. Web matrix is a discontinued cloud-connected website builder and HTML editor
for Windows.
advertisement
6. Which of the following is not a difference between HTML and XHTML?
a) Charset in both html and xhtml is “text/html”
b) Tags and attributes are case-insensitive in HTML but not in XHTML
c) Special characters must be escaped using character entities in XHTML unlike HTML
d) Charset in html is “text/html” where as in xhtml it is “application/xml+xhtml”
View Answer
Answer: a
Explanation: HTML is case insensitive while XHTML is case sensitive. In XHTML,
special characters can be escaped using character entites but not in HTML. Charset in
HTML is “text/html” where as it is “application/xml+xhtml” for XHTML.
7. Which of the following tag is used for inserting the largest heading in HTML?
a) head
b) <h1>
c) <h6>
d) heading
View Answer
Answer: b
Explanation: Headings in HTML starts from <h1> to <h6> in which <h1> heading is the
largest one and <h6> is smallest one among those. The heading tags are <h1> <h2>
<h3> <h4> <h5> and <h6> that are used for the creations of headings.
8. What is DOM in HTML?
a) Language dependent application programming
b) Hierarchy of objects in ASP.NET
c) Application programming interface
d) Convention for representing and interacting with objects in html documents
View Answer
Answer: d
Explanation: The Document Object Model is a cross-platform and language-independent
application programming interface that treats an HTML, XHTML, or XML document as a
tree structure. A document can be viewed as a logical tree with help of DOM Model.
9. In which part of the HTML metadata is contained?
a) head tag
b) title tag
c) html tag
d) body tag
View Answer
Answer: a
Explanation: Metadata is information about data. The meta tag provides metadata/meta
information about the HTML document. Metadata will not be displayed on the page.
Metadata is present in head. The body tag defines document’s body. A title tag is an
HTML element which specifies the title of a web page.
10. Which element is used to get highlighted text in HTML5?
a) <u>
b) <mark>
c) <highlight>
d) <b>
View Answer
Answer: b
Explanation: The <mark> element is used to highlight a section of text. It is useful for
quoting a text or if one wants to bring attention to the text. The <b> tag is used to make
text/paragraph bold. <u> tag is used to underline the text you wanted.
<p>This is the example.<mark> I like this dog. </mark></p>

Output: This is the example. I like this dog.


11. Which of the following is not a HTML5 tag?
a) <track>
b) <video>
c) <slider>
d) <source>
View Answer
Answer: c
Explanation: <video> tag is used to display video clips in HTML5. Multiple media
resources for media elements is specified by <source> tag. Text track for media
elements i.e. <audio> & <video> is provided by <track> tag in HTML5. There is no such
thing as slider tag in HTML5.
12. How do we write comments in HTML?
a) </…….>
b) <!……>
c) </……/>
d) <…….!>
View Answer
Answer: b
Explanation: Browser ignores comment in a code. There are always two types of
command i.e. single line command and multiple line command. If one wants to add a
comment in code, add the text between these characters <!…..comment….>. It will not
visible in the user’s browser.
13. Which of the following elements in HTML5 defines video or movie content?
a) <video>
b) <movie>
c) <audio>
d) <media>
View Answer
Answer: a
Explanation: The media to which linked document is optimized is given by <media> tag.
Before HTML5, videos could only be played with a plug-in (like flash). The HTML5 video
element specifies a standard way to embed a video in a webpage. As like <video>
elements, <audio> element contains additional files or streams like music, recording, etc.
14. Which of the following is not the element associated with the HTML table layout?
a) alignment
b) color
c) size
d) spanning
View Answer
Answer: b
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.
15. Which element is used for or styling HTML5 layout?
a) CSS
b) jQuery
c) JavaScript
d) PHP
View Answer
Answer: a
Explanation: For styling HTML5, CSS i.e Cascading Style Sheet is used. It is style sheet
language and designed to describe presentation of its content including layouts, colors
and fonts. CSS can control the layout of multiple webpages.
16. Which HTML tag is used for making character appearance bold?
a) <u>content</u>
b) <b>content</b>
c) <br>content</br>
d) <i>content</i>
View Answer
Answer: b
Explanation: By enclosing words in the tags <b>and</b> we can make characters
appear bold. <i> element is for content in italics, <u> is for underlined content, <br> is for
vertical breaking.
17. Which HTML tag is used to insert an image?
a) <img url=”htmllogo.jpg” />
b) <img alt=”htmllogo.jpg” />
c) <img src=”htmllogo.jpg” />
d) <img link=”htmllogo.jpg” />
View Answer
Answer: c
Explanation: In HTML, <img> tag is used to insert an image in HTML page. Image tag
has two attributes (src and Alt).
–> Src attribute is used to specify the image path.
–> Alt attribute is used to specify the alternate text for the image.
18. HTML is a subset of ___________
a) SGMT
b) SGML
c) SGME
d) XHTML
View Answer
Answer: b
Explanation: HTML is a subset of SGML. SGML (Standard Generalized Markup
Language) is a standard for specifying a document markup language or tag set.
19. Which character is used to represent when a tag is closed in HTML?
a) #
b) !
c) /
d) \
View Answer
Answer: c
Explanation: The forward-slash (/) is used to indicate the closure of a tag within HTML.
20. Which of the following HTML code will make an image clickable?
a)

<a href="https://www.sanfoundry.com/">Sanfoundry Home Page</a>

b)

<img src="https://www.sanfoundry.com/sanfoundry-logo">
<a href="https://www.sanfoundry.com/">Sanfoundry Home Page</a>
</img>

c)

<a href="https://www.sanfoundry.com/">Sanfoundry Home Page</a>


<img src="https://www.sanfoundry.com/sanfoundry-logo" />

d)

<a href="https://www.sanfoundry.com/"><img
src="https://www.sanfoundry.com/sanfoundry-logo" /></a>

View Answer
Answer: d
Explanation: <a> tag defines a hyperlink, which is used to link from one page to another
page. Suppose if we want an image to be clickable then it should go inside <a> Tag.

21. Among the following, which is the HTML paragraph tag?


a) <p>
b) <pre>
c) <hr>
d) <a>
View Answer
Answer: a
Explanation: <p> tag is used for paragraph in HTML.
22. In HTML, which attribute is used to create a link that opens in a new window tab?
a) src=”_blank”
b) alt=”_blank”
c) target=”_self”
d) target=”_blank”
View Answer
Answer: d
Explanation: Add the target=”_blank” attribute in the Anchor tag. target=”_blank” attribute
makes a link open in a new window tab.
23. Which HTML element is used for short quote?
a) <em>
b) <abbr>
c) <q>
d) <blockquote>
View Answer
Answer: c
Explanation: <em> element indicates emphasis, browser will show the contents of <em>
element in italic. A section which is quoted from another source is specified by
<blockquote>. The <abbr> defines abbreviation. We used <q> element for shorter quote.
Browser put quote around <q> element.
<p>This is a <q>black dog</q>.</p>

Output: This is a “black dog”.


24. Which of the following HTML tag is used to create an unordered list?
a) <ol>
b) <ul>
c) <li>
d) <ll>
View Answer
Answer: b
Explanation: <ul> tag is used to create the unordered list items in an HTML document.
By default, unordered list items will display in a bulleted format.
Different types of unordered list Attribute Values are:
 Disc
 Circle
 Square
 None
Syntax: <ul> Unordered List Items </ul>
25. Which HTML element is used for abbreviation or acronym?
a) <abbr>
b) <blockquote>
c) <q>
d) <em>
View Answer
Answer: a
Explanation: <em> element indicates emphasis, browser will show the contents of <em>
element in italic. We used <q> element for shorter quote. Browser put quote around <q>
element. A section which is quoted from another source is specified by <blockquote>.
For using, abbreviation or acronym <abbr> element is helpful. A title element is to be
used with abbr.
<p>The <abbr title=”Doctor”>Dr.</abbr> is on the way.</p>

Output: The Dr. is on the way.


26. Which of the following HTML tag is used to add a row in a table?
a) <th>
b) <td>
c) <tr>
d) <tt>
View Answer
Answer: c
Explanation: In HTML, <tr> tag is used to create a row in the table. <th> tag is used to
set the header cell of a table.
27. What is the work of <address> element in HTML5?
a) contains IP address
b) contains home address
c) contains url
d) contains contact details for author
View Answer
Answer: d
Explanation: The contact details for author of a page is specified by <address> attribute.
The content is often displayed in italics,
e.g.
<address>
<a href="mailto:enquiry@sanfoundry.com">Sanfoundry</a>
</address>

Output:

Sanfoundry
28. Which of the following tag is used to create a text area in HTML Form?
a) <textarea> </textarea>
b) <text></text>
c) <input type=”text” />
d) <input type=”textarea” />
View Answer
Answer: a
Explanation: The text area tag (<textarea>) is used in a form to declare a text area
element. It allows the user to enter text in multiple rows.
29. To show deleted text, which HTML element is used?
a) <del>
b) <em>
c) <strong>
d) <ins>
View Answer
Answer: a
Explanation: <strong> element shows the importance of text/paragraph between it’s
tags. <em> element indicates emphasis, browser will show the contents of <em>
element in italic. <ins> element shows the content that has been inserted, usually it has
underline. <del> element shows text that has been deleted from, usually it has a line
through the content.
<p>This is <del>not</del> for deletion </p>

Output: This is not for deletion.


30. What is the correct syntax of web address?
a) port://domain.filenmae:path/scheme/prefix
b) prefix://scheme.port:domain/filename/path
c) path://prefix.port:domain/filename/scheme
d) scheme://prefix.domain:port/path/filename
View Answer
Answer: d
Explanation: The correct syntax for a web address is
scheme://prefix.domain:port/path/filename, where scheme is for https or http, prefix is for
domain like www, domain denotes domain name, port defines port number, path defines
path at server, filename is for name of the document.
31. Which tag is used to create a dropdown in HTML Form?
a) <input>
b) <select>
c) <text>
d) <textarea>
View Answer
Answer: b
Explanation: <select> element is used to create a drop-down list in HTML Forms. It is
mainly used to collect user input. Option tags are used within the <select> element to
define available options from the drop-down list.
32. Which tag is used to create a numbered list in HTML?
a) <ol>
b) <ul>
c) <li>
d) <ll>
View Answer
Answer: a
Explanation: <ol> tag is used to create the numbered list or ordered list items in an
HTML document. An ordered list can be numerical or alphabetical order. <li> tag is used
to define each list item.
Syntax: <ol> Ordered List Items </ol>
33. How to create a checkbox in HTML Form?
a) <input type=”text”>
b) <input type=”textarea”>
c) <input type=”checkbox”>
d) <input type=”button”>
View Answer
Answer: c
Explanation: <input type=”checkbox”> is used to create a checkbox in HTML Form.
Checkboxes allow a user to select one or more options of a limited number of choices.
34. How to insert Hyperlink in HTML Page?
a)

<a href="https://www.sanfoundry.com/1000-html-questions-answers/">HTML
MCQ</a>

b)
<a target="https://www.sanfoundry.com/1000-html-questions-answers/" HTML
Quiz />

c)

<a src="https://www.sanfoundry.com/1000-html-questions-answers/">HTML
Test</a>

d)

<a>https://www.sanfoundry.com/1000-html-questions-answers/</a>

View Answer
Answer: a
Explanation: An anchor tag (<a>) and href attribute are used to create a hyperlink in
HTML.

35. Which of the following extension is used to save an HTML file?


a) .hl
b) .h
c) .htl
d) .html
View Answer
Answer: d
Explanation: .html or .htm extensions are used to save the HTML file.
36. Which tag is used to create a blank line in HTML?
a) <b>
b) <br>
c) <em>
d) <a>
View Answer
Answer: b
Explanation: In HTML, <br> tag is used to create a blank line. <b> tag is used to specify
the bold text. <em> tag is used to define the emphasized text.
37. Which HTML tag is used to convert the plain text into italic format?
a) <b>
b) <p>
c) <i>
d) <a>
View Answer
Answer: c
Explanation: In HTML, <i> tag is used to convert the plain text into italic format.
38. What is the use of <hr/> tag in HTML?
a) For making content appearance italics
b) To create vertical rule between sections
c) To create a line break
d) To create horizontal rule between sections
View Answer
Answer: d
Explanation: To create a break between themes-such as a change of topic in a book or a
new scene in a play-you can add a horizontal rule between sections using <hr/> tag
39. Which attribute is not essential under <iframe>?
a) frameborder
b) width
c) height
d) src
View Answer
Answer: a
Explanation: An iframe is equivalent to a window that has been cut into our page, it is
created using <iframe> element. Src, height, width attribute are essentially used inside
of this. Src attribute specifies the URL of the page which is to be shown. Height and
width specify the height and width of an iframe in pixels.
40. Which works similar to <b> element?
a) <blockquote>
b) <strong>
c) <em>
d) <i>
View Answer
Answer: b
Explanation: The words are written inside <strong> can be said with strong emphasis.
Browser shows contents written inside <strong> element in bold.
Example:
<p>1000 <strong>HTML</strong> MCQs.</p>

Output: 1000 HTML MCQs.


41. Which tag is used to underline the text in HTML?
a) <p>
b) <u>
c) <i>
d) <ul>
View Answer
Answer: b
Explanation: In HTML, underline tag (<u>) is used to display the underlined text.
Example: HTML stands for <u>HyperText Markup Language</u>.
42. Which attribute specifies a unique alphanumeric identifier to be associated with an
element?
a) type
b) article
c) id
d) class
View Answer
Answer: c
Explanation: HTML is Hyper Text Markup Language that is used to create web pages
and applications. The id attribute is most used to point to a style in a style sheet, and by
JavaScript (via the HTML DOM) to manipulate the element with the specific id. Class is a
name given to HTML elements that can be used by CSS and JavaScript for styling web
pages. A self-contained content is called an attribute.
43. Which of the following is an HTML specification used to add more information to
HTML tags?
a) Modifydata
b) Minidata
c) Macrodata
d) Microdata
View Answer
Answer: d
Explanation: The Microdata spec provides a standardized syntax for additional semantic
markup to your web pages to enhance the machine readability of your web pages. The
planning for distribution center operation is offered by minidata. Macrodata and
Modifydata are not any terms related to HTML5.
44. Which HTML element is used for YouTube videos?
a) <samp>
b) <small>
c) <frame>
d) <iframe>
View Answer
Answer: d
Explanation: We can host our videos through YouTube and can easily embed them into
our website. <iframe> tag will be used for YouTube videos.
E.g. <iframe width=”670” height=”612” src= “https://sanfoundry.com”>
</iframe>

45. Which of the following HTML element is used for canvas graphics?
a) <css>
b) <paint>
c) <canvas>
d) <graphic>
View Answer
Answer: c
Explanation: CSS i.e. Cascading Style Sheet is a scripting language. Canvas graphics
are introduced in HTML5. Element used for canvas graphics is <canvas>. The HTML
canvas element is used to draw graphics, on the fly, via scripting (usually JavaScript).

JS

1. What is JavaScript?
a) JavaScript is a scripting language used to make the website interactive
b) JavaScript is an assembly language used to make the website interactive
c) JavaScript is a compiled language used to make the website interactive
d) None of the mentioned
View Answer
Answer: a
Explanation: JavaScript is a scripting language used along with HTML and CSS to make
the website interactive along. It is used both on the client-side and server-side.
2. Which of the following is correct about JavaScript?
a) JavaScript is an Object-Based language
b) JavaScript is Assembly-language
c) JavaScript is an Object-Oriented language
d) JavaScript is a High-level language
View Answer
Answer: a
Explanation: Although JavaScript is not an OOP (Object-Oriented Programming)
language like Java or PHP, it is object based language. The standard threesome of
polymorphism, encapsulation, and inheritance are the criteria for object orientation, and
JavaScript fails to meet them.
3. Among the given statements, which statement defines closures in JavaScript?
a) JavaScript is a function that is enclosed with references to its inner function scope
b) JavaScript is a function that is enclosed with references to its lexical environment
c) JavaScript is a function that is enclosed with the object to its inner function scope
d) None of the mentioned
View Answer
Answer: b
Explanation: A closure is a function that is enclosed with references to its lexical
environment. A closure allows an inner function to access the scope of an outside
function. Closures are formed every time a function is created in JavaScript, during
function creation time.
4. What will be the output of the following JavaScript code snippet?

<p id="demo"></p>
var txt1 = "Sanfoundry_";
var txt2 = "Javascriptmcq";
document.getElementById("demo").innerHTML = txt1 + txt2;

a) error
b) Sanfoundry_ Javascriptmcq
c) undefined
d) Sanfoundry_Javascriptmcq
View Answer
Answer: d
Explanation: The + operator in javascript acts as a concatenation operator when used
with string. The new string does not have any space between the two added strings.
advertisement
5. What will be the output of the following JavaScript code?

<p id="demo"></p>
<script>
var js = 10;
js *= 5;
document.getElementById("demo").innerHTML = js;
</script>
a) 10
b) 50
c) 5
d) Error
View Answer
Answer: b
Explanation: The *= operator in javascript is a shorthand expression for the multiplication
of a particular number. It is a combination of two operators * and = .
6. Arrays in JavaScript are defined by which of the following statements?
a) It is an ordered list of values
b) It is an ordered list of objects
c) It is an ordered list of string
d) It is an ordered list of functions
View Answer
Answer: a
Explanation: An array in JavaScript is an ordered list of values, each value is referred to
as an element, and it is identified by an index. An array can include values of many sorts
and the length of an array dynamically sized.
7. What will be the output of the following JavaScript code?

// JavaScript Comparison Operators


function compare()
{
int num=2;
char b=2;
if(a==b)
return true;
else
return false;
}

a) false
b) true
c) compilation error
d) runtime error
View Answer
Answer: b
Explanation: The == in JS convert different types of operands to the same type before
making the comparison. A strict comparison results in true value if the operands are of
the same type and the contents match.
8. What will be the output of the following JavaScript code snippet?

// JavaScript Equalto Operators


function equalto()
{
int num=10;
if(num==="10")
return true;
else
return false;
}
a) false
b) true
c) compilation error
d) runtime error
View Answer
Answer: a
Explanation: A === operator in JS is only true if the operands are of the same type and
the contents match. Two strings are strictly equal when they have the same sequence of
characters, same length, and same characters in corresponding positions.
9. Will the following JavaScript code work?

var js = (function(x) {return x*x;}(10));

a) Exception will be thrown


b) Memory leak
c) Error
d) Yes, perfectly
View Answer
Answer: d
Explanation: For functions expressed as expressions, the function name is optional in
Javascript. Sometimes function expressions are defined and used right away.
10. Which of the following is not javascript data types?
a) Null type
b) Undefined type
c) Number type
d) All of the mentioned
View Answer
Answer: d
Explanation: JavaScript is a dynamic, loosely typed language. Variables in JavaScript
aren’t tied to any specific value type, and each variable can be assigned and reassigned
to values of all the types.
11. Where is Client-side JavaScript code is embedded within HTML documents?
a) A URL that uses the special javascript:code
b) A URL that uses the special javascript:protocol
c) A URL that uses the special javascript:encoding
d) A URL that uses the special javascript:stack
View Answer
Answer: b
Explanation: The Client-side JavaScript code is embedded within HTML documents in
four ways :
1. Inline, between a pair of “script” tags
2. From an external file specified by the src attribute of a “script” tag
3. In an HTML event handler attribute, such as onclick or onmouseover
4. In a URL that uses the special javascript: protocol.
12. What will be the output of the following JavaScript code snippet?

int a=1;
if(a!=null) // JavaScript not equal to Operators
return 1;
else
return 0;

a) 0
b) 1
c) compiler error
d) runtime error
View Answer
Answer: b
Explanation: != is not equal to the operator in Javascript. It gives a value of 1 if the two
values which are compared are not equal and give 0 if the two values are equal.
13. Which of the following object is the main entry point to all client-side JavaScript
features and APIs?
a) Position
b) Window
c) Standard
d) Location
View Answer
Answer: b
Explanation: All client-side JavaScript features and APIs are accessed through the
Window object. It represents a web browser window or frame, and the identifier window
can be used to refer to it.
14. What will be the output of the following JavaScript program?

function sanfoundry(javascript)
{
return (javascript ? “yes” : “no”);
}
bool ans=true;
console.log(sanfoundry(ans));

a) Compilation error
b) Runtime error
c) Yes
d) No
View Answer
Answer: c
Explanation: In javascript, “?” is called the ternary operator which is used for choosing
one choice from the given two choices. It is used instead of if else statement and makes
the code shorter.
15. What will be the output of the following JavaScript code?

// Javascript code snippet to compare the height


function height()
{
var height = 123.56;
var type = (height>=190) ? "tall" : "short";
return type;
}

a) short
b) 123.56
c) tall
d) 190
View Answer
Answer: a
Explanation: The ternary operator in javascript is used as a comparison operator which
works on three operands. The statement in the above code initializes type variable with
the value short which is returned through the function.
16. Which of the following can be used to call a JavaScript Code Snippet?
a) Function/Method
b) Preprocessor
c) Triggering Event
d) RMI
View Answer
Answer: a
Explanation: A function call to the element on which JavaScript is to be run can be used
to invoke JavaScript code. Other techniques include onclick, onload, and onsubmit,
among others.
17. What will be the output of the following JavaScript function?

<p id="demo"></p>
<script>
function javascript()
{
// javacript abs() method
document.getElementById("demo").innerHTML = Math.abs(-7.25);
}
</script>

a) -7.25
b) 7.25
c) -7
d) 7
View Answer
Answer: b
Explanation: The javacript abs() method returns the absolute value of a number. The
method is found in the math library of Javascript.
18. What will be the output of the following JavaScript code?

var a=5 , b=1


var obj = { a : 10 }
// with keyword in JavaScript
with(obj)
{
alert(b)
}

a) 1
b) 10
c) 5
d) Error
View Answer
Answer: a
Explanation: Firstly the interpreter checks obj for property b. But it doesn’t find any
property b so it takes the value from outside the object within the JavaScript code
snippet.
19. Which of the following explains correctly what happens when a JavaScript program
is developed on a Unix Machine?
a) will work perfectly well on a Windows Machine
b) will be displayed as JavaScript text on the browser
c) will throw errors and exceptions
d) must be restricted to a Unix Machine only
View Answer
Answer: a
Explanation: Because JS can run on a variety of operating systems, an application
written for UNIX will run just as well on Windows.
20. Which is a more efficient JavaScript code snippet?
Code 1 :

// for loop in javascript


for(var num=10;num>=1;num--)
{
document.writeln(num);
}

Code 2 :

var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}

a) Code 1
b) Code 2
c) Both Code 1 and Code 2
d) Cannot Compare
View Answer
Answer: a
Explanation: Code 1 would be more efficient JS code. Infact second code will go into
runtime error as the value of num will never reach less than or equal to one.
21. What will be the output of the following JavaScript code?

function printArray(a)
{
var len = a.length, i = 0;
if (len == 0)
console.log("Empty Array");
else
{
// do-while loop in javascript
do
{
console.log(a[i]);
} while (++i < len);
}
}
a) Prints “Empty Array”
b) Prints 0 to the length of the array
c) Prints the numbers in the array in order
d) Prints the numbers in the array in the reverse order
View Answer
Answer: c
Explanation: The do/while statement creates a loop that executes a block of javascript
code once, before checking if the condition is true, then it will repeat the loop as long as
the condition is true. Hence the iterator traverses through the array and print them in
normal order.
22. What happens in the following JavaScript code snippet?

var js = 0;
while (js < 10)
{
console.log(js);
js++;
}

a) An exception is thrown
b) The values of js are logged or stored in a particular location or storage
c) The value of js from 0 to 9 is displayed in the console
d) An error is displayed
View Answer
Answer: c
Explanation: In JavaScript, Console.log is a predefined function that accepts the value
as an argument. At the time of code execution, console.log prints this value in the
argument to the console.
23. What will be the output of the following JavaScript code?

function range(int javascript)


{
int a=5;
for(int i=0;i<javascript;i++)
{
console.log(a);
}
}
range(3);

a) 2
b) 5
c) 555
d) error
View Answer
Answer: c
Explanation: for loop in Javascript first initializes the variable and later on checks for the
condition expression and after that execute the line of statements. The value of iterator i
increase until it reaches the value of length.
24. Which of the following scoping type does JavaScript use?
a) Sequential
b) Segmental
c) Lexical
d) Literal
View Answer
Answer: c
Explanation: JavaScript, like most current programming languages, employs lexical
scoping. This means that functions are performed with the variable scope in effect when
they were defined, rather than the variable scope in effect when they are invoked.
25. What is the basic difference between JavaScript and Java?
a) Functions are considered as fields
b) Functions are values, and there is no hard distinction between methods and fields
c) Variables are specific
d) There is no difference
View Answer
Answer: b
Explanation: Java is an object-oriented programming language, while JS is an object-
oriented scripting language. The main difference between JavaScript and Java is that
functions are values, while methods and fields are not clearly defined.
26. What will be the output of the following JavaScript code?

var quiz=[1,2,3];
var js=[6,7,8];
var result=quiz.concat(js);
document.writeln(result);

a) 1, 2, 3, 6, 7, 8
b) 123
c) 1, 2, 3
d) Error
View Answer
Answer: a
Explanation: concat is a predefined function in the array library in Javascript. The concat
function is used to combine the value of two arrays.
i.e.1, 2, 3, 6, 7, 8
27. Why JavaScript Engine is needed?
a) Both Compiling & Interpreting the JavaScript
b) Parsing the javascript
c) Interpreting the JavaScript
d) Compiling the JavaScript
View Answer
Answer: c
Explanation: For the most part, the JS Engine is used to interpret JavaScript. It’s used to
parse javascript and run it on a web page.
28. What will be the function of the following JavaScript program?

var scope = "js scope";


function checkscope()
{
var scope = "javascript scope";
function f()
{
return scope;
}
return f;
}

a) Returns the value in scope


b) Returns value null
c) Shows an error message
d) Returns exception
View Answer
Answer: a
Explanation: The Lexical Environment is an object that is connected with every
executing function, code block, and the script as a whole in JavaScript. The value in
scope is returned by the code snippet above.
29. What will be the output of the following JavaScript code?

int a=0;
for(a;a<5;a++);
console.log(a);

a) 4
b) 5
c) 0
d) error
View Answer
Answer: b
Explanation: The value of a will increase until it equals 5, at which point the cursor will
exit the loop. Because there are no statements in the for loop, the value of a will only
increase. As a result, the result will be five.
30. Which of the following methods/operation does javascript use instead of == and !=?
a) JavaScript uses equalto()
b) JavaScript uses equals() and notequals() instead
c) JavaScript uses bitwise checking
d) JavaScript uses === and !== instead
View Answer
Answer: d
Explanation: The comma operator, bitwise operators, and the ++ and — operators are
not included in the subset. It also forbids the usage of == and!= due to the type
conversion they do, instead requiring the use of === and!==.
31. What will be the result or type of error if p is not defined in the following JavaScript
code snippet?

console.log(p)

a) Value not found Error


b) Reference Error
c) Null
d) Zero
View Answer
Answer: b
Explanation: Console.log() is a javascript predefined function for printing data or
messages to the console. A reference error will occur if the console.log argument is not
defined.
32. What is the prototype represents in the following JavaScript code snippet?

function javascript() {};

a) Not valid
b) Prototype of a function
c) Function javascript
d) A custom constructor
View Answer
Answer: d
Explanation: All object instances have a constructor property that points to the
constructor function that created them. A custom constructor is a constructor which
requires no arguments and is created automatically by the compiler at the time of object
creation if not created by the user.
33. Why event handlers is needed in JS?
a) Allows JavaScript code to alter the behaviour of windows
b) Adds innerHTML page to the code
c) Change the server location
d) Performs handling of exceptions and occurrences
View Answer
Answer: a
Explanation: JS code can change the behavior of windows, documents, and the
elements that make up those documents via event handlers.
34. Which of the following is not a framework?
a) JavaScript .NET
b) JavaScript
c) Cocoa JS
d) jQuery
View Answer
Answer: b
Explanation: jQuery, which is used in web development, is one of the most popular
frameworks. JavaScript is a scripting language, not a framework, in this case.
35. Which of the following is the property that is triggered in response to JS errors?
a) onclick
b) onerror
c) onmessage
d) onexception
View Answer
Answer: b
Explanation: The Window object’s onerror property acts as an event handler, and it is
triggered when JavaScript problems occur. However, because it is called with various
arguments, it isn’t a genuine event handler.
36. What will be the output of the following JavaScript code?

function compare()
{
int sanfoundry=1;
char javascript=1;
if(sanfoundry.tostring()===javascript)
return true;
else
return false;
}

a) runtime error
b) logical error
c) true
d) false
View Answer
Answer: c
Explanation: The .tostring() function can be used to convert a non-string (integer) to a
string. Only if the operands are of the same type and the contents match is a rigorous
comparison possible. As a result, the following code line will produce true output.
37. What will be the firstname and surname of the following JavaScript program?

var book = {
"main title": "JavaScript",
'sub-title': "The Definitive Guide",
"for": "all audiences",
author: {
firstname: "David",
surname: "Flanagan"
}
};

a) objects
b) property names
c) properties
d) property values
View Answer
Answer: b
Explanation: An item is contained within another object in the code sample above. The
property names are firstname and surname. The value of that property is an object in
and of itself.
38. Which of the following is not an error in JavaScript?
a) Missing of Bracket
b) Division by zero
c) Syntax error
d) Missing of semicolons
View Answer
Answer: b
Explanation: In JavaScript, division by zero does not result in an error; it just returns
infinity or negative infinity. However, because zero divided by zero has no well-defined
value, the result of this operation is the unusual not-a-number value, which is written as
NaN.
39. Consider the following JavaScript statement containing regular expressions and
check if the pattern matches.

var text = "testing: 1, 2, 3";


var pattern = /d+/g;
a) text.check(pattern)
b) pattern.test(text)
c) text==pattern
d) text.equals(pattern)
View Answer
Answer: b
Explanation: The pattern specified is applied to the text included in parenthesis. The
test() method checks a string for a match. If a match is found, this method returns true;
otherwise, it returns false.

CSS
1. What is CSS?
a) CSS is a style sheet language
b) CSS is designed to separate the presentation and content, including layout, colors,
and fonts
c) CSS is the language used to style the HTML documents
d) All of the mentioned
View Answer
Answer: d
Explanation: CSS is a style sheet language that stands for Cascading Style Sheet and is
used to style HTML documents. CSS is mainly designed to separate the presentation
and content, including layout, colors, and fonts.
2. Which of the following tag is used to embed css in html page?
a) <css>
b) <!DOCTYPE html>
c) <script>
d) <style>
View Answer
Answer: d
Explanation: <style> </style> tag is used to embed CSS in HTML page, while <script>
</script> is used to embed JS in HTML. <!DOCTYPE html> is HTML5 declaration.
3. Which of the following CSS selectors are used to specify a group of elements?
a) tag
b) id
c) class
d) both class and tag
View Answer
Answer: c
Explanation: Class selectors are used to specify a group of elements. Id selector
specifies a particular unique element.
4. Which of the following has introduced text, list, box, margin, border, color, and
background properties?
a) HTML
b) PHP
c) CSS
d) Ajax
View Answer
Answer: c
Explanation: CSS is a style sheet language that stands for Cascading Style Sheet. CSS
has introduced text, list, box, margin, border, color, and background properties.
5. Which of the following CSS framework is used to create a responsive design?
a) django
b) rails
c) larawell
d) bootstrap
View Answer
Answer: d
Explanation: Bootstrap is a free and open-source collection of tools for creating websites
and web applications. It contains HTML- and CSS-based design templates for
typography, forms, buttons, navigation and other interface components, as well as
optional JavaScript extensions. It aims to ease the development of dynamic websites
and web applications.
advertisement
6. Which of the following CSS selector is used to specify a rule to bind a particular
unique element?
a) tag
b) id
c) class
d) both class and tag
View Answer
Answer: b
Explanation: For binding a particular unique element, id selectors are used. While for a
group of elements, class selector can be used.
7. Which of the following type of HTML tag is used to define an internal style sheet?
a) <script>
b) <link>
c) <class>
d) <style>
View Answer
Answer: d
Explanation: <style> tag is used to define an internal style sheet in HTML document.
8. Which of the following CSS property is used to make the text bold?
a) text-decoration: bold
b) font-weight: bold
c) font-style: bold
d) text-align: bold
View Answer
Answer: b
Explanation: The font-weight property is used for setting the thickness and boldness of
the font. It is used to define the weight of the text. The available weight depends on the
font-family, which is used by the browser.
9. What will be the output of following CSS code snippet?

h1 {color: "green";}
a) nothings happen
b) error occurs
c) heading becomes dark-green
d) heading becomes green
View Answer
Answer: a
Explanation: Output of the above code snippet won’t happen as the declaration syntax is
wrong. The correct declaration is : h1 { color: green; } which will yield an output. In CSS,
we don’t write the value in double quotes.
10. Which of the following CSS style property is used to specify an italic text?
a) style
b) font
c) font-style
d) @font-face
View Answer
Answer: c
Explanation: font-style property is used to specify an italic text. font-style property has
three values (normal, italic & oblique).
11. What will be the output of following CSS code snippet?

h1 {color: red text-decoration: underline; font-style: italic;}

a) color: red, text-decoration: underline works


b) only font-style: italic works
c) color: red, text-decoration: underline and font-style: italic all works
d) text-decoration: underline and font-style: italic works
View Answer
Answer: b
Explanation: In this case, we should see the browser continue to parse the value of color
as “red text-decoration: underline” before it sees a closing semicolon. The font-style
property that follows would then be used. Because the color property has an illegal
value, it should be ignored.
12. Which of the following are the CSS Extension Prefixes for Webkit?
a) -chrome
b) -web
c) -o-
d) -webkit
View Answer
Answer: d
Explanation: Browser sometimes adds prefixes to non-standard CSS properties. CSS
Extension prefix for Webkit is -webkit which is supported by almost all ios browsers. -o is
used by opera where as -moz is used by firefox browser.
13. Which of the following is the correct syntax to link an external style sheet in the
HTML file?
a) <link rel=”stylesheet” href=”style.css” />
b) <link rel=”stylesheet” src=”style.css” />
c) <style rel=”stylesheet” src=”style.css” />
d) <style rel=”stylesheet” link=”style.css” />
View Answer
Answer: a
Explanation: HTML file must contain a reference to the external style sheet file. External
style sheet files are defined within the <link> element and it should be inside the <head>
section. href attribute specifies the URL of the linked resource.
14. Which of the following is the first CSS specification to become an official W3C
Recommendation?
a) CSS level 2
b) (X)HTML CSS
c) CSS level 1
d) CSS level 2.1
View Answer
Answer: c
Explanation: The first CSS specification to become an official W3C Recommendation is
CSS level 1, published on December 17, 1996. Håkon Wium Lie and Bert Bos are
credited as the original developers.
15. Which of the following function defines a linear gradient as a CSS image?
a) gradient()
b) linear-gradient()
c) grayscale()
d) image()
View Answer
Answer: b
Explanation: linear-gradient() function defines a linear gradient as a CSS image.
Creating a linear gradient function we should define minimum of two color stops. color
stops will tell the browser which colors to use in the gradients for smooth transitions.
16. Which of the following CSS property can be used to set the image as a border
instead of the border style?
a) background-image-source
b) background-image
c) border-image-source
d) border-image
View Answer
Answer: c
Explanation: The border-image-source property specifies the path to the image to be
used as a border (instead of the normal border around an element).
17. Which of the following CSS property defines the different properties of all four sides
of an element’s border in a single declaration?
a) border-collapse
b) border-width
c) padding
d) border
View Answer
Answer: b
Explanation: The border-width property sets the width of an element’s four borders. This
property can have from one to four values.
18. Which of the following is the correct way to apply CSS Styles?
a) in an external CSS file
b) inside an HTML element
c) inside the <head> section of an HTML page
d) all of the mentioned
View Answer
Answer: d
Explanation: We can style the document using CSS in three different ways i.e embed,
inline and external. An inline CSS means applying styles rules directly to the HTML
element. In embed, we declare or write all the needed style in <style></style> tag in the
head section of the HTML document. We can create an external style sheet and provide
its link to the document.
19. Which of the following CSS property sets the font size of text?
a) font-size
b) text-size
c) text
d) size
View Answer
Answer: a
Explanation: CSS Syntax:
font-size: length | percentage | larger | smaller | xx-small | x-small |
small | medium | large | x-large | xx-larger | inherit

20. Which of the following is not the property of the CSS box model?
a) margin
b) color
c) width
d) height
View Answer
Answer: b
Explanation: CSS box model include height, width, padding, margin and border. All text-
fields have complete support for every property related to CSS box model. Browser
relies on system default styles when displaying these widgets.
21. Which of the following CSS property sets what kind of line decorations are added to
an element, such as underlines, overlines, etc?
a) text-decoration
b) text-style
c) text-decoration-line
d) text-line
View Answer
Answer: c
Explanation: The text-decoration-line property defines the type of line decorations that
are added to an element, such as underlines, overlines, etc.
22. Which of the following CSS property specifies the look and design of an outline?
a) outline-style
b) outline-format
c) outline-font
d) none of the mentioned
View Answer
Answer: a
Explanation: The outline-style CSS property is used to set the style of the outline of an
element. An outline is a line that is drawn around elements, outside the border edge, to
make the element stand out.
23. What will be the output of the following CSS code snippet?
span {
border: 1px solid red;
outline: green dotted thick;
}

a) All span elements will have a green thick border and a red outline
b) All span elements will have a red border and a green dotted outline
c) All span elements will have a outer green dotted border and an inner red border
d) All span elements will have an outer red border and inner green dotted border
View Answer
Answer: c
Explanation: The border property creates the inner border, while the outline sets the
outer border.
24. Which of the following CSS property sets the shadow for a box element?
a) set-shadow
b) box-shadow
c) shadow
d) canvas-shadow
View Answer
Answer: b
Explanation: box-shadow property sets the shadow for a box element.
CSS Syntax:
box-shadow: none | inherit

25. Which of the following CSS property is used to set the color of the text?
a) text-decoration
b) pallet
c) colour
d) color
View Answer
Answer: d
Explanation: The color property is used to set the color of the text. In CSS, colors can
also be specified using RGB values, RGBA values, HSL values, HEX values, etc.
26. Which of the following CSS Property controls how an element is positioned?
a) static
b) position
c) fix
d) set
View Answer
Answer: b
Explanation: Position property controls how an element is positioned. When set to
absolute or fixed, the element is removed completely from the normal flow of the
document. When set to relative, the element is moved relative to its position in the
normal flow, but a space is left where it would normally have been. The default value,
static, means the element remains in the normal flow and is not positioned.
27. Which of the following CSS selector selects the elements that are checked?
a) :checked
b) E ~ F
c) ::after
d) none of the mentioned
View Answer
Answer: a
Explanation: :checked selector selects the elements that are checked.
Example: :checked {color: blue;}

28. Which of the following is an appropriate value for the overflow element?
a) scroll
b) hidden
c) auto
d) all of the mentioned
View Answer
Answer: d
Explanation: Overflow of a div or a container can have the following values:
visible|hidden|scroll|auto|initial|inherit

29. Which of the following CSS property is used to specify table borders in CSS?
a) table:border
b) table
c) border
d) none of the mentioned
View Answer
Answer: c
Explanation: In CSS, border property is used to specify table borders.
Example:
table{border: 7px solid black;}

30. Which of the following property is used to align the text in a table?
a) text-align
b) align
c) text
d) none of the mentioned
View Answer
Answer: a
Explanation: In CSS, text-align property is used to align the text in a table.
Example:
table{text-align: left;}

31. Which of the following CSS Property sets the stacking order of positioned elements?
a) y-index
b) z-index
c) x-index
d) all of the mentioned
View Answer
Answer: b
Explanation: z-index property sets the stacking order of positioned elements.
Syntax:
z-index: auto|number|initial|inherit;

32. What will be the output of the following CSS code?

div {
border-width:5px;
border-style:dotted solid double dashed;
}
a) Box having dotted bottom outline, solid right outline, double top outline and dashed
left outline
b) Box having dotted bottom outline, solid left outline, double top outline and dashed left
outline
c) Box having dotted top outline, solid right outline, double bottom outline and dashed
left outline
d) Box having dotted top outline, solid left outline, double bottom outline and dashed
right outline
View Answer
Answer: c
Explanation: The shorthand run in clockwise direction.
33. Which of the following property allows a marquee to be used in the case of a text-
overflow?
a) overflow-marquee
b) overflow-style
c) overflow-text
d) none of the mentioned
View Answer
Answer: b
Explanation: overflow-style is a CSS property that allows a marquee to be used in the
case of a text-overflow.
Syntax:
overflow-style: auto | marquee-block

34. Which of the following CSS property defines the space between cells in a table?
a) border-spacing
b) border-style
c) border
d) none of the mentioned
View Answer
Answer: a
Explanation: border-spacing property defines the space between cells in a table.
Syntax:
border-spacing: non-negative length(s) | inherit

35. Which of the following CSS3 property can be used to allow line breaks within words?
a) line-break
b) line-wrap
c) word-wrap
d) word-break
View Answer
Answer: d
Explanation: word-break property can be used to allow line breaks within the words.
Syntax:
word-break: break-all | keep-all | normal

PHP
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
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
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
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
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
18. What will be the output of the following PHP code snippet?

<?php
$url = "phpmcq@sanfoundry.com";
echo ltrim(strstr($url, "@"),"@");
?>

a) phpmcq@sanfoundry.com
b) php@sanfoundry.com
c) phpmcq@
d) sanfoundry.com
View Answer
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

You might also like