Ans: ECMAScript (European Computer Manufacturers Association) Script is a specification for the scripting language standards. It has standardized Javascript which made Javascript the best implementation of ECMAScript.
Ans: There are three possible ways of defining a variable in Javascript (i) var (which is used from the beginning) (ii) const (iii) let. The last two ways are the latest ways of defining a variable and are introduced in ES-2015(ES6 version).
Ans: Local Storage will stay until it is manually cleared through settings or program.
Session Storage will leave when the browser is closed.
List some of the Javascript frameworks.
There are many Javascript Frameworks available today, but the most commonly used frameworks are:
Ans: The keyword var is from the beginning of Javascript; whereas, let is introduced in ES2015/ES6. The keyword let has a block scope; whereas, the keyword var has a functional scope.
Ans: JavaScript uses a hierarchical structure, applicable to all the objects created in a document. Following are the objects, used in JavaScript that shows the relationship of one object to another.
Ans: JavaScript supports three Primary, two Composite and two Special data types. Next, we list down the data types in each of the categories.
Primary Data Types:
Composite Data Types:
Special Data Types:
Ans: All the prime languages use ‘this’ keyword to refer to an object that is currently instantiated by the class. However, in JavaScript, ‘this’ refers to an object which ‘owns’ the method. Though this varies, with how a function call happens.
Ans: The operator '==' compares the value; whereas, the operator '===' compares both value and type.
Ans: When used the typeof operator on null; i.e., typeof(null), the value is an object. Whereas, when used the typeof operator on undefined; i.e., typeof(undefined), the value would be undefined.
Ans: There are several differences between let and var. let gives you the privilege to declare variables that are limited in scope to the block; statement of expression, unlike var. var is rather a keyword, which defines a variable globally regardless of block scope.
Ans: There are two main ways to create an array in JavaScript
The Array constructor method has three different syntaxes. If we call the constructor with two or more arguments, it declares an array with array elements also initialized. If we provide only one argument to the Array constructor, it refers to the length of the new array with, elements not initialized. Lastly, the constructor without any argument creates an array with its length set to zero with elements not initialized.
Examples:
var myArray4 = new Array(1,2,3,4,5) // an array with 5 elements
var myArray5 = new Array(20) // an empty array of length 20
var myArray6 = new Array() // an empty array of length 0
Ans: A cookie is a piece of data which is sent from a website (that owns the requested web page) and gets stored locally by the browser at the user end. Cookies are needed because HTTP protocol which arranges for the transfer of web pages to your browser, is stateless. It means that HTTP has no way to keep track of the activities performed by the user at an earlier point in time. One way to resolve this issue is by using cookies. It contains the following data.
When a request arrives at the server for a web page that maintains a cookie, the server appends the cookie to the HTTP header to send it across. The server-side programs can then read out the information included in it and decide that you have the right to view the page or not and other user preferences.
Thus, every time you visit the site that maintains the cookies, your information is available there.
Below rules to be followed while naming the variables in JavaScript:
Ans: Strict Mode imposes a layer of constraint on JavaScript. It provides following enhancements.
To enable strict mode, we have to add, “use strict” directive to the code. The physical location of the “strict” directive determines its scope. If used at the beginning of the js file, its scope is global. However, if we declare strict mode at the first line in the function block, its scope restricts to that function only.
Ans: In JavaScript, there is some cool stuff that makes it the best of all. One of them is the Delegation Model. When capturing and bubbling, allow functions to implement one single handler to many elements at one particular time then that is called event delegation. Event delegation allows you to add event listeners to one parent instead of specified nodes. That particular listener analyzes bubbled events to find a match on the child elements.
Ans: Closures are the combination of lexical environment and function within which the function was declared. This allows JavaScript programmers to write better, more creative, concise and expressive codes. The closure will consist of all the local variables that were in scope when the closure was created. Sure, closures appear to be complex and beyond the scope, but after you read this article, closures will be much more easy to understand and more simple for your every day JavaScript programming tasks. JavaScript is a very function-oriented language it gives the user freedom to use functions as the wish of the programmer.
Ans: Every JavaScript function has a prototype property (by default this property ise null), that is mainly used for implementing inheritance. We add methods and properties to a function’s prototype so that it becomes available to instances of that function. Let’s take an example that calculates the perimeter of a rectangle.
function Rectangle(x, y) {
this.x = x;
this.y = y;
}
Rectangle.prototype.perimeter = function() {
return 2 * (this.x + this.y);
}
var rect = new Rectangle(4, 2);
console.log(rect.perimeter()); // outputs '12'
Ans: In Javascript close() method is used to close the current window. You must write window.close() to ensure that this command is associated with a window object and not some other JavaScript object.
Ans: import * as object name from ‘./file.js’ is used to import all exported members as an object. You can simply access the exported variables or methods using dot (.) operator of the object.
Example:
objectname.member1;
objectname.member2;
objectname.memberfunc();
Ans: Imports and exports helps us to write modular javascript code. Using Imports and exports we can split our code in to multiple files. Imports allows to take only some specific variables or methods of a file. We can import methods or variables that are exported by a module.See the below example for more detail.
//index.js
import name,age from './person';
console.log(name);
console.log(age);
//person.js
let name ='Sharad',
occupation='developer'
age =26;
export { name, age};
Related Interview Questions...
Core Java Interview Questions And Answers
Core Java Programming Interview Questions and Answers
Multithreading in Java Interview Questions and Answers
Java Interview Questions and Answers
Java/J2EE Apps Integration Questions and Answers.
Java Collections Interview Question and Answers
Interview Questions For Selenium with Java