JavaScript Questions & Answers – Scripting CSS

«
»

This set of Javascript Multiple Choice Questions & Answers (MCQs) focuses on “Scripting CSS”.

1. Which syntax is used to describe elements in CSS?
a) Protectors
b) Selectors
c) Both Protectors and Selectors
d) Protectors or Selectors
View Answer

Answer: b
Explanation: CSS stylesheets have a very powerful syntax, known as selectors, for describing elements or sets of elements within a document.
advertisement

2. What does the following JavaScript code snippet mean?

#log>span

a) Span child after log declaration
b) Specific span child of id greater than log
c) Span child less than log
d) Any span child of the element with id as log
View Answer

Answer: d
Explanation: The above code snippet means that any span child of the element with id=”log”.
advertisement
advertisement

3. Which of the following is the ultimate element selection method?
a) querySelectorAll()
b) querySelector()
c) queryAll()
d) query()
View Answer

Answer: a
Explanation: querySelectorAll() is the ultimate element selection method: it is a very powerful technique by which client-side JavaScript programs can select the document elements that they are going to manipulate.
advertisement

4. Which of the following is the Web application equivalent to querySelectorAll()?
a) #()
b) &()
c) $()
d) !()
View Answer

Answer: c
Explanation: Web applications based on jQuery use a portable, cross-browser equivalent to querySelectorAll() named $().

5. The C in CSS stands for _______________
a) Continuous
b) Cascaded
c) Contentional
d) Cascading
View Answer

Answer: d
Explanation: The C in CSS stands for “cascading”. This term indicates that the style rules that apply to any given element in a document can come from a “cascade” of different sources.
advertisement

6. The first version of CSS is _____________
a) CSS1
b) CSS2
c) CSS3
d) CSS
View Answer

Answer: a
Explanation: The first version of CSS is CSS1. It was officially released in the year 1996.

7. Which of the following is not an example of a Shortcut Property?
a) border
b) font
c) text
d) value
View Answer

Answer: d
Explanation: border, font & text are shortcut properties. For example, the font-family, font-size, font-style, and font-weight properties can all be set at once using a single font property with a compound value:

advertisement
font: bold italic 24pt helvetica;

8. Which of the following is the default positioning elements with CSS?
a) relative
b) static
c) absolute
d) fixed
View Answer

Answer: b
Explanation: static is the default value and specifies that the element is positioned according to the normal flow of document content (for most Western languages, this is left to right and top to bottom).

9. Which property lays the element according to the normal flow?
a) relative
b) absolute
c) fixed
d) static
View Answer

Answer: a
Explanation: When the position property is set to relative, an element is laid out according to the normal flow, and its position is then adjusted relative to its position in the normal flow.

10. Which of the following property allows you to specify an element’s position with respect to the browser window?
a) relative
b) fixed
c) static
d) absolute
View Answer

Answer: b
Explanation: The fixed value allows you to specify an element’s position with respect to the browser window. Elements with fixed positioning are always visible and do not scroll with the rest of the document. Like absolutely positioned elements, fixed-position elements are independent of all others and are not part of the document flow.

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

<p id="demo"></p>
<script>
var x = 'It\'s';
document.getElementById("demo").innerHTML = x ; 
</script>

a) It\’s
b) ‘It\’s’
c) It’s
d) Error
View Answer

Answer: c
Explanation: If an apostrophe is present in the string then a backslash is added before it. The string skips the execution of the character after a backslash.

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

<p id="demo"></p>
<script>
var pos = str.indexOf("locate");
document.getElementById("demo").innerHTML = pos;
</script>

a) 5
b) 7
c) 0
d) Error
View Answer

Answer: b
Explanation: The indexOf() method returns the position of the first occurrence of a specified text. locate occurs first time at 7 positions.

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

<button onclick="myFunction()">Try it</button>
<p id="demo">one</p>
<script>
function myFunction() 
{
   var str = document.getElementById("demo").innerHTML; 
   var txt = str.replace("one","two");
   document.getElementById("demo").innerHTML = txt;
}
</script>

a) one
b) two
c) error
d) undefined
View Answer

Answer: b
Explanation: The replace function replaces string data with a specified value. The innerHtml function changes the value of data in the paragraph.

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

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() 
{
   var str = "The rain in SPAIN stays mainly in the plain"; 
   var res = str.match(/z/);
   If(res)
      res=true;
   Else
      res=false;
   document.getElementById("demo").innerHTML = res;
}
</script>

a) True
b) False
c) Error
d) Handling
View Answer

Answer: b
Explanation: The match method finds for a match in the given string. Since z is not present in the string, the output will be false.

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

<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() 
{
   var str = "a,b,c,d,e,f";
   var arr = str.split(",");
   document.getElementById("demo").innerHTML = arr[3];
}
</script>

a) d
b) a
c) b
d) c
View Answer

Answer: a
Explanation: The split function splits the string according to the argument passed to it. The third index of the array will be initialized with d, hence the output will be d.

Sanfoundry Global Education & Learning Series – Javascript Programming.

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

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter