Strict mode is a way to introduce better error-checking into your code. When you use strict mode, you cannot use implicitly declared variables, or assign a value to a read-only property, or add a property to an object that is not extensible. You can enable strict mode by adding “use strict” at the beginning of a file, a program, or a function.
2.What is ECMAScript?
ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications.
NaN property represents “Not-a-Number” value. It indicates a value which is not a legal number.
typeof of a NaN will return a Number .
To check if a value is NaN, we use the isNaN() function,
4.What is negative Infinity?
Some of the key benefits of strict mode include:
Makes debugging easier. Code errors that would otherwise have been ignored or would have failed silently will now generate errors or throw exceptions, alerting you sooner to problems in your code and directing you more quickly to their source.
A prompt box is a box which allows the user to enter input by providing a text box. The prompt() method displays a dialog box that prompts the visitor for input. A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either “OK” or “Cancel” to proceed after entering an input value.
Another feature of this technique is to allow for an easy alias for a global variable. This is often used in jQuery plugins.
8.What is Callback?
The simplest way to create a cookie is to assign a string value to the document.cookie object, which looks like this-
document.cookie = "key1 = value1; key2 = value2; expires = date";
Functions that operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.
11.Explain “this” keyword.
The “this” keyword refers to the object that the function is a property of.
The value of “this” keyword will always depend on the object that is invoking the function.
The silly way to understanding the this keyword is, whenever the function is invoked, check the object before the dot . The value of this . keyword will always be the object before the dot .
Currying is an advanced technique to transform a function of arguments n, to n functions of one or less arguments.
13.What is memoization?
Memoization is a form of caching where the return value of a function is cached based on its parameters. If the parameter of that function is not changed, the cached version of the function is returned.
By using memoization we can store(cache) the computed results based on the parameters. If the same parameter is used again while invoking the function, instead of computing the result, we directly return the stored (cached) value.
14.What is the difference between == and ===?
== is the abstract equality operator while === is the strict equality operator.
The == operator will compare for equality after doing any necessary type conversions.
The === operator will not do type conversion, so if two values are not the same type === will simply return false.
15.What are the new features in ES6 or ECMAScript 2015?
- Arrow Functions
- Template Strings
- Enhanced Object literals
- Object Destructuring
- Default Function parameters
- Rest and Spread Operators
- Block Scoping with let and const
The scope of a variable is the region of your program in which it is defined.
Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
We use escape characters backslash (\) while working with special characters, such as ampersands (&), apostrophes (‘), double quotes (“ ”), and single quotes (‘ ’).
- \b – Backspace
- \f – Form feed
- \n – Newline
- \r – Carriage return
- \t – Horizontal tabulator
- \v – Vertical tabulator
These aren’t in anyway executed in the HTML or JS code.
These were originally designed for controlling fax machines, teletypes, and typewriters.
19.What is a prompt box?
A prompt box is a box that allows the user to enter input by providing a text box. A label and box will be provided to enter the text or number.
The parseInt() function is used to convert numbers between different bases. parseInt() takes the string to be converted as its first parameter. The second parameter is the base of the given string.
To convert 4F (or base 16) to integer, the code used will be -
parseInt ("4F", 16);
Content is replaced everywhere
We cannot use it like "appending to innerHTML
Even if you use +=like "innerHTML = innerHTML + 'html'" still the old content is replaced by html
The entire innerHTML content is re-parsed and builds into elements. Therefore, it's much slower
The innerHTML does not provide validation, and therefore we can potentially insert valid and broken HTML in the document and break it
These are stated below.
Separation of code is done.
Code Maintainability is easy.
The performance is better.
Using the ‘debugger’ keyword in the code is like using breakpoints in the debugger.
To test the code, the debugger must be enabled for the browser. If debugging is disabled for the browser, the code will not work. During debugging of the code, the remaining part should stop executing, before it goes to the next line.
24.What are Self Invoking Functions?
They are also known as ‘Immediately Invoked Function Expressions’ or ‘Self Executing Anonymous Functions’. These functions are invoked automatically in the code, hence they are named as ‘Self Invoking Functions’.
Usually, we define a function and invoke it, but if we want to execute a function automatically where it is explained, and if we are not going to call it again, we can use anonymous functions. And these types of functions have no name.
25.What is the difference between ‘null’ and ‘undefined’?
Both keywords represent empty values.
The differences are:
- In ‘undefined’, we will define a variable, but we won’t assign a value to that variable.
- On the other hand, in ‘null’ we will define a variable and assign the ‘null’ value to the variable.