970_90

Tuesday, 5 April 2016

Javascript Interview Questions And Answers for 4 year experienced

Javascript Interview Questions And Answers for 4 year experienced

Question: How to remove an item from javaScript Array?
var myArray = new Array('a', 'b', 'c', 'd');
var index = myArray.indexOf('b');
myArray.splice(myArray, 1);
console.log(myArray);



Question: How to call a function after 2 section?
function myFunctionName(){
    //console.log('called after 2 sec of page load');
}
setTimeout(myFunctionName,2000);



Question: How to start/stop setInterval function?
function myFunctionName(){
    //console.log('called after 2 sec of page load');
}
var refreshIntervalObject =setInterval(myFunctionName, 3000);
clearInterval(refreshIntervalObject);



Question: What is basic difference between $(document).ready() and window.onload?
$(document).ready(): This event occurs after the HTML document has been loaded.
window.onload This event when all content (e.g. html, js, images) also has been loaded.


Question: Is JavaScript a pass-by-reference OR pass-by-value?
passed by reference


Question: How to send cross domain Ajax Request?
You can send ajax request with "JSONP" only in Cross Domain.
$.ajax({
    url: '/ajax',
    dataType: 'jsonp',
    success:function(data, textStatus, request){
      console.log(request.getResponseHeader('some_header'));
    
    }
});   



Question: What is CDATA? When it is required?
CDATA stand for "Character Data" and it means that the data in between tags.
CDATA is required when you need an document to parse as XML.


Question: How to compare two Dates in javaScript?
var date1 = new Date();
var date2 = new Date(d1);
if(d1.getTime() === d2.getTime()){
    /* Both Time are are Same **/
}else{
    /* Time are are Different**/
}



Question: How to merge two array?
var array1 = ["One","Two"];
var array2 = ["Three", "Four"];
var mergeArray = array1.concat(array2);
console.log(mergeArray);



Question: How to use Regular Expression in JavaScript?
var searchString= '12 34';
var result=searchString.match( /\d+/g ) 
console.log(result ); //["12", "34"]
console.log(result.length+' Elements matched'); //2 Elements matched



Question: How to trigger ENTER key was pressed?
var code = e.keyCode || e.which; if(code == 13) { /** Enter key is pressed **/ }


Question: How to select element by Name?
var arrChkBox = document.getElementsByName("elementName");
Question: How to Convert character to ASCII code in JavaScript?
var characterString='$';
characterString.charCodeAt(0);//36



Question: What do you mean by "javascript:void(0)"?
javascript:void(0) means "DO Nothing";
for example:
<a href="javascript:void(0)">No effect on clicking</a>



Question: Can we detect, if javaScript is enabled?
Yes, we can do with html tag.
<noscript>
    javascript is not enabled, Please enable javascript in your browser.
</noscript>



Question: How to add element in the begining OR at the end of array?
var myArray = new Array('a', 'b', 'c', 'd');
myArray.push('end');
myArray.unshift('start');
console.log(myArray);