10 Common JavaScript Interview Questions and How to Answer Them

Get a head start on your next job interview with this guide to the most common JavaScript questions and how to answer them

Table of contents

No heading

No headings in the article.

  1. What is the difference between a block element and an inline element? Give a few examples of block and inline tags which we have in HTML.
    ( HTML me block aur inline elements ka kya fark hai? Kuch block aur inline tags ke examples bataye )

    • The Main difference between a block element and an inline element is that block takes up the full width of the parent container and creates a new line after them while inline elements only take up as much width of their content and do not create a new line.

    • Examples of block elements include <h1> , <p>, <div> while examples of inline elements include <span>, <a>, <img>.

    • ( Block elements aur inline elements HTML me do tarah ke elements hote hai jo alag alag display properties rakhte hai. Block elements apne parent container ke full width ko occupy karte hai aur unke baad ek new line create karte hai. Examples <h1> , <p>, <div>.

    • Inline elements sirf apni content ke width aur height ke sath hote hai. Ye mostly text based tags ke liye use kiye jate hai. Examples <span>, <a>, <img>)

  2. What are pseudo-elements and pseudo-classes in CSS? Give some examples.
    ( CSS me pseudo-elements aur pseudo-classes kya hai? Kuchh examples de. )

    • Pseudo-elements are used to select a specific part of elements and are denoted with a double colon (::).

    • For Example, ::before and ::after can be used to add content before and after an element, ::first-line and ::first-letter can be used to style the first letter or line of an element.

    • Pseudo-classes are used to select an element based on its state and properties and are denoted with a single colon (:)

    • For Example, :hover, :active, :visited etc.

    • ( Pseudo elements kisi specific part ko select karne ke liye use kiye jate hai. Jaise ::before, ::after, ::first-line and ::first-letter.

    • Pseudo classes kisi element ko unke state or position ke base par select karne ke liye use kiye jate hai, jaise :hover, :active, :visited, :focus and :checked. )

  3. What are CSS positions? What are the position types in CSS? What is the default position property in CSS?
    ( CSS me position kya hota hai? CSS me Kaun si position types hoti hai? CSS me default position property kya hai? )

    • CSS positions are used to set the position of an element. The position types are static, relative, absolute, fixed and sticky.

    • The default position property is static which means the element is positioned in the normal flow of the document.

    • Relative positions allow you to offset an element from its current position.

    • Absolute positions allow you to set the element at a specific location on the screen.

    • Fixed positions fix the element at a specific location on the screen.

    • Sticky positions allow the element to remain in a specific location until a certain point is reached while scrolling.

    • ( CSS me position kisi element ko specific place par set karna hota hai. Position types - static, relative, absolute, fixed, sticky hai.

    • Static position default hai, jisme element normal flow me position hota hai.

    • Relative position me hum element ke current position se offset de sakte hai.

    • Absolute position me hum element ko specific coordinates par set kar sakte hai.

    • Fixed position me hum element ko browser window ke fixed position par set kar sakte hai, ye element window scroll hote hue bhi same position par rahega.

    • Sticky position me hum element ko normal flow me rakhte hue usko specific point tak scroll hote hue stick kar sakte hai. )