Wednesday, 25 May 2016

JavaScript Interview Questions and Answers for Experienced 2016

JavaScript Interview Questions and Answers for Experienced 2016

Question: How to Get class name using jQuery?
className = $('#IdWhichClassNameWantToGet').attr('class');



Question: How to check a div having class name or Not?
className = $('#IdWhichClassNameWantToCheck').hasClass('hasClass');



Question: How to add a focus on inputbox?
className = $('input#inputBoxId').focus();



Question: How to add X number of days in date?
var dateObject = new Date();
dateObject.setDate(dateObject.getDate()+5); //Add 5 Days



Question: How to add X number of minutes in date?
var dateObject = new Date();
dateObject.setDate(dateObject.getTime()+(30 * 60 * 1000)); //Add 30 Minutes



Question: How to delete an element from Associate Array?
var myArray = new Object();
myArray["firstname"] = "Arun";
myArray["lastname"] = "Kumar";
myArray["age"] = "26";
console.log(myArray); /* Object { firstname="Arun",  lastname="Kumar",  age="26"} */
delete myArray["age"];//Delete an Element
console.log(myArray); /*  Object { firstname="Arun",  lastname="Kumar"} */
Question: How to exit from for loop from JS?
Use return true to exit from loop. For Example:
for (i = 0; i < 5; i++) { 
    if(i>2){
        break;
    }    
}



Question: How to load a noimage.gif, If there we are unable to load images?
Use return true to exit from loop. For Example:
<img onerror="this.onerror=null;this.src=&#39;/images/noimage.gif&#39;;" src="/images/actualimage.jpg" />



Question: How to change the image source with jQuery?
Use return true to exit from loop. For Example:
$("#imageElement").attr("src","/folder/image.jpg");



Question: How to get image Height & Width?
var img = document.getElementById('imageId'); 
var width = img.clientWidth; //this is image width
var height = img.clientHeight; //this is image height



Question: How to Format a number with exactly two decimals in JavaScript?
Use return true to exit from loop. For Example:
var num = 6.42003;
alert(num.toFixed(2)); // "6.42"



Question: How to prevent buttons from submitting forms?
Use return true to exit from loop. For Example:
<form method="post" onsubmit="return saveDatainDb()">
First name:  <input name="firstname" type="text" /><br />
Last name:<br />
<input name="lastname" type="text" />

<input name="submit" type="submit" value="Save Data" />

</form>
<script>
function saveDatainDb(){
    /** Validate , if not valid return false**/
    validation_false=true;
    If(validation_false){
        return false;
    }
    /** Validate , if not valid return false**/


    /** Write here code for AJax call**/
 
    /** Write here code for AJax call**/


}
</script>



Tuesday, 24 May 2016

MySQL Interview Questions and Answers for 3 year experience

MySQL Interview Questions and Answers for 3 year experience

Question: How can I enable Slow MySQL's query log?
Just set the global variable as following:
SET GLOBAL slow_query_log = 'ON';



Question: How to trim the white space from values?
 UPDATE tablename set name = TRIM(name);



Question: How to add more values in enum field?
ALTER TABLE tablename MODIFY COLUMN country ENUM('india','usa','uk','china');



Question: How do I check if an index exists on a table field in MySQL?
SHOW INDEX FROM tablename



Question: What is the maximum length of data I can put in a BLOB column in MySQL?
A BLOB - 65535 bytes maximum
A MEDIUMBLOB - 16777215 bytes maximum
A LONGBLOB - 4294967295 bytes maximum


Question: How to check empty field in Mysql
select * from where 1 AND (email != "" AND email IS NOT NULL);



Question: How to display current connection info?
SELECT USER();



Question: How to display List of database with current connection?
SELECT DATABASE();



Question: How to get count of distinct record?
 select count(distinct email) from users



Question: How to get count of distinct record?
 UPDATE users SET   email = NULL WHERE  id = 1000;



Question: How to copy data from one table to another table?
INSERT INTO table2 (id,uid,changed,status,assign_status) SELECT id,uid,now(),'Pending','Assigned' FROM table1



Question: How to get a list of MySQL views?
SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';



Question: How to Copy table without copying data?
CREATE TABLE users_bck SELECT * FROM users WHERE 1=0;



Question: How to Repair all tables?
mysqlcheck -A --auto-repair;



Question: How to increase MySQL connection timeout?
Open MySQL file and increase the following
ini_set('mysql.connect_timeout', 600);//20 min
ini_set('default_socket_timeout', 600); //20 MIn



Question: Which MySQL datatype for an IP address?
As per me, It should be Int(11) unsigned.


Question: How to get last 30 days record?
SELECT  * FROM    users WHERE   created_date < DATE_ADD(NOW(), INTERVAL +1 MONTH);

Here created_date id datetime field in which we store the insertion date.


Question: Differences between utf8 and latin1?
In latin1 each character is exactly one byte long.
In utf8 a character can consist of more than one byte.



Question: How to convert the data type from one to another?
Convert String to DateTime
SELECT CONVERT('2017-04-06 08:25:57', DATETIME); //'2017-04-06 08:25:57'

Convert String to Time
SELECT CONVERT('06:07:58', TIME); //06:07:58

Convert Number to String
SELECT CONVERT(125, CHAR);  //125




Question: How to convert the Convert Character Sets from one to another?
SELECT CONVERT('hello user, how are you?' USING utf8); //



Question: How to get datetime when it was in another format?
SELECT STR_TO_DATE('18,05,2017','%d,%m,%Y'); //2017-05-18