Js Interview Qa
Js Interview Qa
jslogo
JavaScript is a popular web scripting language used for client-side and server-side
development. Its code can be inserted into HTML pages and understood and executed
by web browsers. JavaScript also supports object-oriented programming abilities.
2. What’s the difference between JavaScript and Java?
JavaScript
Java
Java applications are generally made for use in operating systems and virtual
machines.
JavaScript does not need compilation before running the application code.
Java source code needs a compiler before it can be ready to run in realtime.
3. What are the various data types that exist in JavaScript?
JavaScript adds interaction to otherwise static web pages and makes them react to
users’ inputs.
Quick Feedback
There is no need for a web page to reload when running JavaScript. For example,
form input validation.
Rich User Interface
JavaScript helps in making the UI of web applications look and feel much better.
Frameworks
JavaScript has countless frameworks and libraries that are extensively used for
developing web applications and games of all kinds.
6. How do you create an object in JavaScript?
const student = {
name: 'John',
age: 17
}
7. How do you create an array in JavaScript?
Here is a very simple way of creating arrays in JavaScript using the array literal:
var a = [];
Built-in Method
Values
Date()
concat()
push()
round()
length()
The scope of a variable implies where the variable has been declared or defined in
a JavaScript program. There are two scopes of a variable:
Global Scope
Local variables are accessible only within a function in which they are defined.
10. What is the ‘this’ keyword in JavaScript?
In JavaScript, functions are objects and therefore, functions can take other
functions as arguments and can also be returned by other functions.
callback.J
All modern web browsers, such as Chrome, Firefox, etc., have an inbuilt debugger
that can be accessed anytime by pressing the relevant key, usually the F12 key. The
debugging tools offer several features.
We can also debug JavaScript code inside a code editor that we use to develop a
JavaScript application, such as Visual Studio Code, Atom, Sublime Text, etc.
Take the Leap and Master Java Development
Java Certification TrainingENROLL NOW
Take the Leap and Master Java Development
14. What is the difference between Function declaration and Function expression?
Function declaration
Function expression
Created when the execution point reaches it; can be used only after that
Example:
function abc() {
return 5;
Example:
return 5;
}
15. What are the ways of adding JavaScript code in an HTML file?
We can write JavaScript code within the script tag in the same HTML file; this
is suitable when we need just a few lines of scripting within a web page.
We can import a JavaScript source file into an HTML document; this adds all
scripting capabilities to a web page without cluttering the code.
Here are some intermediate-level JavaScript interview questions and answers for you
to prepare for your interviews.
16. What do you understand about cookies?
browser-cookies
Fig: Browser cookies
A cookie is generally a small data that is sent from a website and stored on the
user’s machine by a web browser that was used to access the website. Cookies are
used to remember information for later use and also to record the browsing activity
on a website.
17. How would you create a cookie?
Reading a cookie using JavaScript is also very simple. We can use the
document.cookie string that contains the cookies that we just created using that
string.
To delete a cookie, we can just set an expiration date and time. Specifying the
correct path of the cookie that we want to delete is a good practice since some
browsers won’t allow the deletion of cookies unless there is a clear path that
tells which cookie to delete from the user’s machine.
function delete_cookie(name) {
}
20. What’s the difference between let and var?
Both let and var are used for variable and method declarations in JavaScript. So
there isn’t much of a difference between these two besides that while var keyword
is scoped by function, the let keyword is scoped by a block.