SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
JavaScript Interview Q's
1) What is JavaScript? What are the advantages and dis advantages of Java script?
Ans) It is a client side scripting language. It is used to create interactive websites. It was
developed by Brendan Eich.
JavaScript is a loosely typed or a dynamic type language. That means you don't need to
specify type of the variable because type will get determined automatically while the program
is being processed.
Advantages:
1. Client side validations
2. No server burden
3. Develop desktop Widgets
4. Display Popup and Dialog boxes
Dis Advantages:
1. Cross Browser Dependent Issues
2. If we disables JavaScript, then there is no action events.
3. No security code..
2) Diff b/w undefined and not defined?
Ans) Undefined: variable was declared ( with the statement-keyword 'var' ), but not
assigned with a value.
var my_var;
Not defined:- A not defined is a variable which is not declared at a given point of time with
declaration keyword like var, let or const.
console.log(a);
var a = 5;
//Output:- undefined
3) Diff b/w undefined and null?
Ans) Undefined means a variable has been declared but has not yet been assigned a value. On
the other hand, null is an assignment value. It can be assigned to a variable as a representation of no
value.
Also, undefined and null are two distinct types: undefined is a type itself (undefined) while
null is an object
JavaScript Interview Q's
4) What are the differences between == and ===?
Ans) “ ==” Operator Checks Only Data But “===” Operator Checks Data And Type Also.
5) What are the data types used in JavaScript?
Ans) There are two types of data types in JavaScript.
1. Primitive : String, Number, Boolean, Undefined, Null
2. Non-Prmitive / reference : Object, Array, RegExp
Example:
-----------
var length = 16; // Number
var lastName = "info"; // String
var person; // undefined
var person = null; // null
var y = true; // Boolean
var course = ["java", ".net", "UI"]; // Array
var x = {firstName:"getsure", lastName:"info"}; // Object
var patt = /getsure/ig;
6) What is Object? How many ways to create objects in JavaScript?
Ans) JavaScript objects are combination of properties (key & value) and methods.
The value can be a primitive type, an object or a function. Properties can be added,
updated, removed at any time and some are read only.
Note: Do Not Declare String, Number And Boolean As Objects As Complicate Your Code
And Slow Down Execution Speed
There are 3 ways to create objects:
1. By object literal
2. By using an object constructor (using new keyword)
3. By creating instance of Object directly (using new keyword)
JavaScript Interview Q's
7. What does "1"+2+4 evaluate to? What does 3+4+"7" evaluate to?
Ans) Anything which follows string is converted to String.
Hence, "1" is string, and the digits 2 and 4 which comes
after this, also become part of string only.
So the answer is 124
Since 3 and 4 are integers, they will be added numerically. And since 7 is a string, its
concatenation will be done. So the result would be 77.
8) Does JavaScript Support automatic type conversion, If yes give example.
Ans) Yes! Javascript support automatic type conversion. It is most common way of type
conversion used by Javascript developers.
Example:
alert( typeof 3.14)=number
9) Explain about String properties and methods?
Ans) It is an object that represents a sequence of characters. It is used for storing and
manipulating text.
➢ charAt(index) : method returns the character at the given index
➢ concat(str) : concatenates or joins two strings.
➢ indexOf(str) : method returns the index position of the given string
➢ lastIndexOf(str): method returns the last index position of the given string.
➢ toLowerCase()/toUpperCase() toLowerCase() : method returns the given string in
lowercase/uppercase letters.
➢ trim(): method removes leading and trailing whitespaces from the string
➢ replace() method: It replaces the value with specified value or regex.
10) What is Closure? Explain briefly?
Ans) Closure is an inner function that has access to the outer function's variables in
addition to its own variables and global variables.
The inner function has access not only access to the outer function variables, but also outer
function's parameters. We can create a closure by adding a function inside another function.
JavaScript Interview Q's
Example:
Var z=10;
function outerFunction(x) {
var tmp = 3;
function innerFunction(y) {
document.write(z+x + y + tmp); // will print 20
}
innerFunction(5);
}
outerFunction(2);
11) How to add a method to already defined class (What is Prototype)
Ans) It is also an object. All JavaScript objects inherit their properties and methods from
their prototype. By using prototype we can add properties and methods at runtime
Note: prototype is similar to classes in Es6 on words
Employee.prototye.myObject=”Charan Kumar”
12) What is Array? What are the methods available? Diff b/w Slice and Splice
methods?
Ans) It is an indexed collection of fixed number of homogenous data elements. Simply, It is
used to store multiple values in a single variable.
Methods:
❖ pop() : method removes the last element from an array:
❖ push(): method adds a new element to an array (at the end):
❖ unshift(): Method is used to add new items to the beginning of an array.
❖ shift() :Method is used to Remove the first item of an array
❖ delete fruits[0] is also used for delete the particular Index element.
❖ sort(): method sorts an array alphabetically:
❖ reverse(): method reverses the elements in an array.
❖ concat() : method creates a new array by concatenating two arrays:
❖ splice() : method can be used to add /remove items to/from an array.
// 1st parameter indicates index and 2nd parameter indicates how many
elements u have to remove.
❖ slice() : method slices out a piece of an array into a new array
// from nth index to (n-1)th index but in slice() last index is excluding .
JavaScript Interview Q's
13) What is the use of "Use Strict"?
Ans) The purpose of "use strict" is to indicate that the code should be executed in "strict
mode".
14) One object properties / functions, how can we use in other functions (Diff b/w
call, apply, bind)
Ans)
Call ():
var obj = {name:"Charan"};
var myscript = function(a,b,c){
return "welcome "+this.name+" to "+a+" "+b+" institute"+c;
};
console.log(myscript.call(obj,"Your","New"," Getsureinfo "));
// returns output as welcome Charan to Your New institute Getsureinfo.
Apply ():
var obj = {name:"Charan"};
var myscript = function(a,b,c){
return "welcome "+this.name+" to "+a+" "+b+" institute"+c;
};
// array of arguments to the actual function
var args = ["Your "," New "," Getsureinfo "];
console.log(myscript.apply(obj,args));
// returns output as welcome Charan to Your New institute Getsureinfo.
Bind ():
var obj = {name:"Charan"};
var myscript = function(a,b,c){
return "welcome "+this.name+" to "+a+" "+b+" institute"+c;
};
//creates a bound function that has same body and parameters
var bound = myscript.bind(obj);
console.dir(bound); ///returns a function
console.log(bound ("Your "," New "," Getsureinfo "));
// returns output as welcome Charan to Your New institute Getsureinfo.
JavaScript Interview Q's
15) Diff b/w forEach, for in and for of?
Ans) ForEach: : Foreach Is An Array Method That We Can Use To Execute A Function
On Each Element In An Array. It Can Only Be Used On Arrays, Maps, And Sets.
Example:
const arr = ['cat', 'dog', 'fish'];
arr.forEach(element => {
console.log(element);
});
// cat
// dog
// fish
For…In: For...in Is Used To Iterate Over The Enumerable Properties Of Objects. Every
Property In An Object Will Have An Enumerable Value — If That Value Is Set To True,
Then The Property Is Enumerable.
Example:
const obj = {
a: 1,
b: 2,
c: 3,
d: 4
}
for (let elem in obj) {
console.log( obj[elem] )
}
// 1
// 2
// 3
// 4
For of: for of is a new way for iterating collections. Its introduced in ES6, whereas
forEach is only for arrays. forEach gives you access to the index, if you want it, whereas
for..of does not.
JavaScript Interview Q's
Example:
const obj = {
a: 1,
b: 2,
c: 3,
d: 4
}
for (let elem of obj) {
console.log( elem )
}
// 1
// 2
// 3
// 4
16) What is Inheritance. Explain both inheritances?
Ans) Parent Object Properties and methods may acquire(access) from the child object is
nothing but inheritance.
❖ __Proto__
❖ Prototype and Call()
❖ Object.Creat()
❖ Es6 Classes
❖ TypeScript Interfaces
17) Explain function hoisting in JavaScript?
Ans) By default At Run Time, In JavaScript, Moves All The Function Declarations To The
Top Of The Current Scope. This Is Called Function Hoisting. This Is The Reason JavaScript
Functions Can Be Called Before They Are Defined.
Note: Function Hoisting is not applicable for Anonymous function expressions.
Example:
1. Defining a function then calling it:
function addition(firstNumber, secondNumber) {
var sum = firstNumber + secondNumber;
JavaScript Interview Q's
return sum;
}
var result = addition(10,20);
document.write("Result value---->"+result);
2. Function call is present before the function definition:
var result = addition(10,20);
document.write("Result value---->"+result);
function addition(firstNumber, secondNumber) {
var sum = firstNumber + secondNumber;
return sum;
}
18) What is event bubbling and capturing?
Ans) Event bubbling and capturing are two ways of event propagation in the HTML DOM
API, when an event occurs in an element inside another element, and both elements have
registered a handle for that event.
19) What does Object.create do?
Ans) Object.Create Method Is Another Method To Create New Object In Javascript.
object.create(Prototype_object, Propertiesobject)
Object.create Methods Accepts Two Arguments:
• Prototypeobject: Newly Created Objects Prototype Object. It Has To Be An
Object Or Null.
• Propertiesobject: Properties Of The New Object. This Argument Is Optional
Example:
var person = Object.create(null);
typeof(person) // Object
console.log(person) // Object with prototype object as null
// Set property to person object
person.name = "Virat";
console.log(person) // Object with name as property and prototype as null
JavaScript Interview Q's
20) Difference between freeze and seal methods?
Ans) Object. Seal:
▪ It prevents adding and/or removing properties from the sealed object; using
delete will return false
▪ It makes every existing property non-configurable: they cannot be converted from
'data descriptors' to 'accessor descriptors' (and vice versa), and no attribute of
accessor descriptors can be modified at all (whereas data descriptors can change
their writable attribute, and their value attribute if writeable is true).
▪ Can throw a TypeError when attempting to modify the value of the sealed object
itself (most commonly in strict mode)
Object. Freeze:
• Exactly what Object.seal does, plus:
• It prevents modifying any existing properties
• Neither one affects 'deep'/grandchildren objects (e.g. if obj is frozen or sealed, obj.el
can't be changed, but obj.el.id can).
Freeze: makes the object immutable, meaning no change to defined property allowed,
unless they are objects.
Seal: prevent addition of properties, however defined properties still can be changed.

Contenu connexe

Tendances

Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariSurekha Gadkari
 
Arrays searching-sorting
Arrays searching-sortingArrays searching-sorting
Arrays searching-sortingAjharul Abedeen
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipesKnoldus Inc.
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanKavita Ganesan
 
1. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES61. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES6pcnmtutorials
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Aijaz Ali Abro
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List Hitesh-Java
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions WebStackAcademy
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data TypesTareq Hasan
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets Hitesh-Java
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorKamal Acharya
 

Tendances (20)

Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
 
Angular Introduction By Surekha Gadkari
Angular Introduction By Surekha GadkariAngular Introduction By Surekha Gadkari
Angular Introduction By Surekha Gadkari
 
Expressjs
ExpressjsExpressjs
Expressjs
 
List in Python
List in PythonList in Python
List in Python
 
Arrays searching-sorting
Arrays searching-sortingArrays searching-sorting
Arrays searching-sorting
 
Angular directives and pipes
Angular directives and pipesAngular directives and pipes
Angular directives and pipes
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
 
1. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES61. Arrow Functions | JavaScript | ES6
1. Arrow Functions | JavaScript | ES6
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
Object Oriented Javascript
Object Oriented JavascriptObject Oriented Javascript
Object Oriented Javascript
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
Javascript
JavascriptJavascript
Javascript
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 

Similaire à JavaScript(Es5) Interview Questions & Answers

Similaire à JavaScript(Es5) Interview Questions & Answers (20)

JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
 
Java
JavaJava
Java
 
Ajax and JavaScript Bootcamp
Ajax and JavaScript BootcampAjax and JavaScript Bootcamp
Ajax and JavaScript Bootcamp
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
C++ theory
C++ theoryC++ theory
C++ theory
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
javascript
javascript javascript
javascript
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
C questions
C questionsC questions
C questions
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 

Dernier

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 

Dernier (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 

JavaScript(Es5) Interview Questions & Answers

  • 1. JavaScript Interview Q's 1) What is JavaScript? What are the advantages and dis advantages of Java script? Ans) It is a client side scripting language. It is used to create interactive websites. It was developed by Brendan Eich. JavaScript is a loosely typed or a dynamic type language. That means you don't need to specify type of the variable because type will get determined automatically while the program is being processed. Advantages: 1. Client side validations 2. No server burden 3. Develop desktop Widgets 4. Display Popup and Dialog boxes Dis Advantages: 1. Cross Browser Dependent Issues 2. If we disables JavaScript, then there is no action events. 3. No security code.. 2) Diff b/w undefined and not defined? Ans) Undefined: variable was declared ( with the statement-keyword 'var' ), but not assigned with a value. var my_var; Not defined:- A not defined is a variable which is not declared at a given point of time with declaration keyword like var, let or const. console.log(a); var a = 5; //Output:- undefined 3) Diff b/w undefined and null? Ans) Undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value. Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object
  • 2. JavaScript Interview Q's 4) What are the differences between == and ===? Ans) “ ==” Operator Checks Only Data But “===” Operator Checks Data And Type Also. 5) What are the data types used in JavaScript? Ans) There are two types of data types in JavaScript. 1. Primitive : String, Number, Boolean, Undefined, Null 2. Non-Prmitive / reference : Object, Array, RegExp Example: ----------- var length = 16; // Number var lastName = "info"; // String var person; // undefined var person = null; // null var y = true; // Boolean var course = ["java", ".net", "UI"]; // Array var x = {firstName:"getsure", lastName:"info"}; // Object var patt = /getsure/ig; 6) What is Object? How many ways to create objects in JavaScript? Ans) JavaScript objects are combination of properties (key & value) and methods. The value can be a primitive type, an object or a function. Properties can be added, updated, removed at any time and some are read only. Note: Do Not Declare String, Number And Boolean As Objects As Complicate Your Code And Slow Down Execution Speed There are 3 ways to create objects: 1. By object literal 2. By using an object constructor (using new keyword) 3. By creating instance of Object directly (using new keyword)
  • 3. JavaScript Interview Q's 7. What does "1"+2+4 evaluate to? What does 3+4+"7" evaluate to? Ans) Anything which follows string is converted to String. Hence, "1" is string, and the digits 2 and 4 which comes after this, also become part of string only. So the answer is 124 Since 3 and 4 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 77. 8) Does JavaScript Support automatic type conversion, If yes give example. Ans) Yes! Javascript support automatic type conversion. It is most common way of type conversion used by Javascript developers. Example: alert( typeof 3.14)=number 9) Explain about String properties and methods? Ans) It is an object that represents a sequence of characters. It is used for storing and manipulating text. ➢ charAt(index) : method returns the character at the given index ➢ concat(str) : concatenates or joins two strings. ➢ indexOf(str) : method returns the index position of the given string ➢ lastIndexOf(str): method returns the last index position of the given string. ➢ toLowerCase()/toUpperCase() toLowerCase() : method returns the given string in lowercase/uppercase letters. ➢ trim(): method removes leading and trailing whitespaces from the string ➢ replace() method: It replaces the value with specified value or regex. 10) What is Closure? Explain briefly? Ans) Closure is an inner function that has access to the outer function's variables in addition to its own variables and global variables. The inner function has access not only access to the outer function variables, but also outer function's parameters. We can create a closure by adding a function inside another function.
  • 4. JavaScript Interview Q's Example: Var z=10; function outerFunction(x) { var tmp = 3; function innerFunction(y) { document.write(z+x + y + tmp); // will print 20 } innerFunction(5); } outerFunction(2); 11) How to add a method to already defined class (What is Prototype) Ans) It is also an object. All JavaScript objects inherit their properties and methods from their prototype. By using prototype we can add properties and methods at runtime Note: prototype is similar to classes in Es6 on words Employee.prototye.myObject=”Charan Kumar” 12) What is Array? What are the methods available? Diff b/w Slice and Splice methods? Ans) It is an indexed collection of fixed number of homogenous data elements. Simply, It is used to store multiple values in a single variable. Methods: ❖ pop() : method removes the last element from an array: ❖ push(): method adds a new element to an array (at the end): ❖ unshift(): Method is used to add new items to the beginning of an array. ❖ shift() :Method is used to Remove the first item of an array ❖ delete fruits[0] is also used for delete the particular Index element. ❖ sort(): method sorts an array alphabetically: ❖ reverse(): method reverses the elements in an array. ❖ concat() : method creates a new array by concatenating two arrays: ❖ splice() : method can be used to add /remove items to/from an array. // 1st parameter indicates index and 2nd parameter indicates how many elements u have to remove. ❖ slice() : method slices out a piece of an array into a new array // from nth index to (n-1)th index but in slice() last index is excluding .
  • 5. JavaScript Interview Q's 13) What is the use of "Use Strict"? Ans) The purpose of "use strict" is to indicate that the code should be executed in "strict mode". 14) One object properties / functions, how can we use in other functions (Diff b/w call, apply, bind) Ans) Call (): var obj = {name:"Charan"}; var myscript = function(a,b,c){ return "welcome "+this.name+" to "+a+" "+b+" institute"+c; }; console.log(myscript.call(obj,"Your","New"," Getsureinfo ")); // returns output as welcome Charan to Your New institute Getsureinfo. Apply (): var obj = {name:"Charan"}; var myscript = function(a,b,c){ return "welcome "+this.name+" to "+a+" "+b+" institute"+c; }; // array of arguments to the actual function var args = ["Your "," New "," Getsureinfo "]; console.log(myscript.apply(obj,args)); // returns output as welcome Charan to Your New institute Getsureinfo. Bind (): var obj = {name:"Charan"}; var myscript = function(a,b,c){ return "welcome "+this.name+" to "+a+" "+b+" institute"+c; }; //creates a bound function that has same body and parameters var bound = myscript.bind(obj); console.dir(bound); ///returns a function console.log(bound ("Your "," New "," Getsureinfo ")); // returns output as welcome Charan to Your New institute Getsureinfo.
  • 6. JavaScript Interview Q's 15) Diff b/w forEach, for in and for of? Ans) ForEach: : Foreach Is An Array Method That We Can Use To Execute A Function On Each Element In An Array. It Can Only Be Used On Arrays, Maps, And Sets. Example: const arr = ['cat', 'dog', 'fish']; arr.forEach(element => { console.log(element); }); // cat // dog // fish For…In: For...in Is Used To Iterate Over The Enumerable Properties Of Objects. Every Property In An Object Will Have An Enumerable Value — If That Value Is Set To True, Then The Property Is Enumerable. Example: const obj = { a: 1, b: 2, c: 3, d: 4 } for (let elem in obj) { console.log( obj[elem] ) } // 1 // 2 // 3 // 4 For of: for of is a new way for iterating collections. Its introduced in ES6, whereas forEach is only for arrays. forEach gives you access to the index, if you want it, whereas for..of does not.
  • 7. JavaScript Interview Q's Example: const obj = { a: 1, b: 2, c: 3, d: 4 } for (let elem of obj) { console.log( elem ) } // 1 // 2 // 3 // 4 16) What is Inheritance. Explain both inheritances? Ans) Parent Object Properties and methods may acquire(access) from the child object is nothing but inheritance. ❖ __Proto__ ❖ Prototype and Call() ❖ Object.Creat() ❖ Es6 Classes ❖ TypeScript Interfaces 17) Explain function hoisting in JavaScript? Ans) By default At Run Time, In JavaScript, Moves All The Function Declarations To The Top Of The Current Scope. This Is Called Function Hoisting. This Is The Reason JavaScript Functions Can Be Called Before They Are Defined. Note: Function Hoisting is not applicable for Anonymous function expressions. Example: 1. Defining a function then calling it: function addition(firstNumber, secondNumber) { var sum = firstNumber + secondNumber;
  • 8. JavaScript Interview Q's return sum; } var result = addition(10,20); document.write("Result value---->"+result); 2. Function call is present before the function definition: var result = addition(10,20); document.write("Result value---->"+result); function addition(firstNumber, secondNumber) { var sum = firstNumber + secondNumber; return sum; } 18) What is event bubbling and capturing? Ans) Event bubbling and capturing are two ways of event propagation in the HTML DOM API, when an event occurs in an element inside another element, and both elements have registered a handle for that event. 19) What does Object.create do? Ans) Object.Create Method Is Another Method To Create New Object In Javascript. object.create(Prototype_object, Propertiesobject) Object.create Methods Accepts Two Arguments: • Prototypeobject: Newly Created Objects Prototype Object. It Has To Be An Object Or Null. • Propertiesobject: Properties Of The New Object. This Argument Is Optional Example: var person = Object.create(null); typeof(person) // Object console.log(person) // Object with prototype object as null // Set property to person object person.name = "Virat"; console.log(person) // Object with name as property and prototype as null
  • 9. JavaScript Interview Q's 20) Difference between freeze and seal methods? Ans) Object. Seal: ▪ It prevents adding and/or removing properties from the sealed object; using delete will return false ▪ It makes every existing property non-configurable: they cannot be converted from 'data descriptors' to 'accessor descriptors' (and vice versa), and no attribute of accessor descriptors can be modified at all (whereas data descriptors can change their writable attribute, and their value attribute if writeable is true). ▪ Can throw a TypeError when attempting to modify the value of the sealed object itself (most commonly in strict mode) Object. Freeze: • Exactly what Object.seal does, plus: • It prevents modifying any existing properties • Neither one affects 'deep'/grandchildren objects (e.g. if obj is frozen or sealed, obj.el can't be changed, but obj.el.id can). Freeze: makes the object immutable, meaning no change to defined property allowed, unless they are objects. Seal: prevent addition of properties, however defined properties still can be changed.