Important JavaScript Interview Questions In Hindi

Image could not load

Image on pixabay

interviewer द्वारा JavaScript में सबसे ज्यादा questions Variables , Operators , Data types , loop , functions , Array, BOM और DOM से होते हैं , इस article में ऐसे कुछ important questions answers के साथ बताएंगे।

1. Variable length argument function in JS

Answer : Actually normal functions को जब हम define करते थे तो
हमें need के according parameters भी define करते थे , और उस function को Call करते समय हमें उसी के accordingly values / arguments भी pass किये जाते थे।

अब अगर हमें ये नहीं मालूम हो कि function call करते समय
कितने arguments pass हो रहे हैं , इस तरह के functions को handle करने के लिए हमें JavaScript ने facility provide की है Variable Length Arguments की . जिसकी help से हम pass किये गए सभी arguments / values को easily handle कर सकते हैं।

variable length of arguments को handle करने के दो तरीके है -

  1. Using arguments Object .

  2. By prepending triple dots(...) in parameter.

function test_fun(...value_ar) { console.log(arguments); console.log(value_ar); } /*call function by passig some arrgument*/ test_fun(2,3,4,5,6); test_fun(10, 20, 30);

Output :

{ 0: 2, 1: 3, 2: 4, 3: 5, 4: 6}
[ 2, 3, 4, 5, 6 ]
{ 0: 10, 1: 20, 2: 30}
[ 10, 20, 30 ]

2. What are Arrow Functions ?

Answer : जब हमें short expression calculate / evaluate करना हो तो complete function define करने के जगह Arrow Function use कर सकते हैं।

Arrow Function में curly braces और return keyword की जरूरत नहीं पड़ती है। Arrow Function में direct parenthesis के बाद expression लिखते हैं , और expression evaluate होकर automatically return हो जाता है।

let test = () => "Hello World !"; console.log(test());

Output :

Hello World !

Note* Arrow Function , Anonymous Function का ही Shorter version है। Generally Arrow Function तभी use करते हैं जब हम one line expression evaluate करना हो , But अगर कही भी multi-line expressions / statements हैं तो arrow (=>) के बाद curly braces के अंदर सभी expressions / statements return statement के साथ लिखते हैं।

Read more about arrow functions ..

3. What are Callback Functions In JS

Callback Functions वो function होते हैं जो किसी दूसरे function में as an arguments pass किये जाते हैं। और जिस function में ये pass किये जाते हैं उन्हें Higher - Order Function कहते हैं।

Need Of Callback Function In JS

हम जानते हैं कि JavaScript Synchronous Scripting language है , means code Top -Down order में run होता है। But कई cases में code Asynchronously भी run होता है।

Actually जब हम setTimeOut() या await() function का use करके Asynchronously Code run करते हैं , तो वो code of block run होने से पहले ही उससे आगे का Code execute होने लगता है। जिसकी वजह से program में कभी-कभी errors भी आ जाती हैं या logic के according code run नहीं होता है। इसीलिए callback functions का use किया जाता है।

function do_sum(num1, num2, callback) { var sum = 0; /*delay execution for 1 second*/ setTimeout(function(){ sum = num1 + num2; /*here call callback function and pass the result*/ callback(sum) }, 1000); } var sum = do_sum(10, 20, function(result){ console.log("Result : ", result); });

Output

Result : 30

Read more about callback functions ...

4. Can we modify constant array ?

Yes, हम किसी constant array को modify कर सकते हैं , हम new item को insert कर सकते हैं या किसी existing element को remove भी कर सकते हैं।

const arr = ["Banana", "Apple"]; console.log("Original Array : ", arr); // insert item. arr.push("Kiwi"); console.log("After Insert : ", arr); // remove first item. arr.shift(); console.log("After Remove : ", arr);

Output

Original Array :  [ "Banana", "Apple" ]
After Insert :  [ "Banana", "Apple", "Kiwi" ]
After Remove :   [ "Apple", "Kiwi" ]

आप सिर्फ constant array के elements को modify कर सकते हैं , लेकिन उस constant array variable में कोई new value नहीं assign नहीं कर सकते हैं।

5. Can we modify constant Object

Yes, हम किसी constant Object को modify कर सकते हैं , हम new property को add कर सकते हैं या किसी existing property को delete भी कर सकते हैं।

const obj = { name : "Rahul", address : "UP, India" }; console.log("Original : ", obj); // add new property. obj.profession = "Developer"; console.log("After Add : ", obj); // delete property. delete obj.address; console.log("After Remove : ", obj);

Output :

Original :   { name: "Rahul", address: "UP, India" }
After Add :  { name: "Rahul", address: "UP, India", profession: "Developer" }
After Remove :  { name: "Rahul", profession: "Developer" }

6. Function prototype in JS

किसी Function instance की prototype data property तब किया जाता है जब function as a constructor को new operator के साथ use किया जा रहा है। या वह function एक Object की तरह use में लिया जा रहा हो।

function prototype का main purpose किसी function के constructor में new properties को add करना है , चूंकि properties constructor में add हो रही हैं इसका मतलब है कि ये properties सभी object instances के साथ share / accessible होंगी।

// define function function Speak() { // code. } // add a function to constructor. Speak.prototype.say = function() { console.log("Hello world !"); } // create 2 instances. let obj1 = new Speak(); let obj2 = new Speak(); // call function with both instances. obj1.say(); obj2.say();

Output :

Hello world !
Hello world !

7. What is BOM (Browser Object Model) ?

BOM ( Browser Object Model ) का use browser से interact करने के लिए किया जाता है। Browser के लिए default object window object होता है , means इसकी सभी properties और methods को directly access कर सकते हैं।

BOM ( Browser Object Model ) का root window object होता है , जो कि current open window / Tab की properties Show करता है। इसके 5 और children object हैं -

  1. document

  2. history

  3. screen

  4. location

  5. navigator

8. window Object in JS

window Object, Current Browser window represent करता है , window object browser द्वारा automatically create किया जाता है।
window की कई properties और methods हैं , कुछ important methods इस प्रकार हैं -

  1. open()

  2. close()

  3. alert()

  4. confirm()

  5. prompt()

  6. setTimeout()

9. JS history Object

history object , user द्वारा visit किये गए सभी URLs को contain करता है। इसके कई useful methods और properties होती हैं, जिनकी help से हम आसानी से visit किये गए URLs पर navigate कर सकते हैं। इसके कुछ important methods इस प्रकार हैं -

  1. length : length property हमें visit किये URLs की length return करता है।

  2. back() : history.back() method का use , previous visited page पर से फिर जाने के लिए किया जाता है।

  3. forward() : history.back() की तरह forward() का use next page visit करने के लिए किया जाता है।

  4. go() : back() और forward() का use , previous और next URL visit करने के लिए किया जाता है , But history.go() method का use करके हम किसी particular URL को visit कर सकते हैं।

10. JS navigator Object

JavaScript में window.navigator object का use browser detection
के लिए किया जाता है , इस object की help से browser की information like (browser name , version , user agent etc .) get कर सकते हैं। हालाँकि window.navigator property read only है , means window Object की तरह user इसकी values को set नहीं कर सकता है।

11. What is DOM (Document Object Model) ?

DOM (Document Object Model) , web page का object-oriented representation है जिसे scripting language like JavaScript के through change किया जा सकता है।

ये web pages को Objects और Nodes में represent करते हैं। कोई भी web page एक document है जो कि browser window या HTML Sources के रूप में हो सकता है।

document Object , web page और HTML को manipulate करने के लिए कई सारी properties और methods provide कराता है -

  1. getElementById()

  2. getElementByClassName()

  3. getElementByTagName()

  4. querySelector()

  5. querySelectorAll()

Read more about DOM and their elements ...

11. What are events ?

Event किसी भी हो रहे Action के लिए एक signal है, जिससे पता चलता है कि कोई action perform हुई है । या simply कह सकते हैं कि Events actions या occurrence होती हैं।
JavaScript में ऐसी बहुत सी Events हैं , उनमे से कुछ General & Daily bases पर use होने वाली events इस प्रकार हैं।

  1. onload

  2. onclick

  3. onsubmit

  4. onkeydown

  5. onkeypress

  6. onkeyup

Read more about events ...

12. What is event Listener ?

Basically Event Listeners , किसी selected element में event को Attach या Detach करते हैं। HTML Element में Event Attach या Detach करने के लिए normally दो function use हैं -

  • addEventListener

  • removeEventListener

Read more about event Listeners ...

I Hope, JavaScript के बारे में ये छोटा सा article आपको पसंद आया होगा , हम आपको highly recommend करते हैं basic JavaScript interview questions के लिए।

Recent Blogs

Loading ...

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook