Question 1. How can an object be created in JavaScript?

  •    var emp = {
  • name: “James”
  • age: 25
  • };

 

 

Answer. The concept of object is supported by JavaScript very well. By using the literal object, an object can be created in JavaScript, as mentioned.

 

Question 2. What are the arguments objects, and how to convert an idea to a normal function in JavaScript?

Answer. JavaScript variable arguments are the arguments transferred to a process. The type of operator allows us to obtain the types of arguments assigned to the role.

 

Question 3. Describe the scope of a variable in javascript?

Answer. The scope of a variable is the state of the program that defines it. There are just two scopes for JavaScript variables.

Global variables: The global variable’s scope is widespread globally, which means it is visible in all JavaScript code. 

Local variable: A local variable is only visible in the function in which it is defined. Function parameters are always local parameters of the procedure.

Question 4. Briefly describe the purpose of the “This” operator in JavaScript.

Answer. In JavaScript, the critical term “This” refers to the object to which it belongs. It has distinct values depending on the purpose of its usage. For example, it refers to the primary thing in a method and the global object in a function.

 

Question 4. Give some examples of converting non-Boolean values ​​into boolean values.

Answer. The query appears if a non-boolean value is converted to a boolean, whether it becomes or false, accordingly?

The particular listing of “false” values in JavaScript is given below:

  • 0, -0, NaN (invalid numbers)
  • “” (empty string)
  • null, undefined
  • false

Each value that is not in the “false” list is considered “true.” Examples are as follows:

  • function foo() { .. } (functions)
  • { }, { a: 42 } (objects)
  • [ ], [ 1, “2”, 3 ] (arrays)
  • 42
  • “hello”
  • True

Question 5. Differentiate between Java and JavaScript?

Answer. Java is an entire programming language. In contrast, JavaScript is a coded software that may bring to HTML pages. These languages aren’t in any respect inter-based and are designed for one-of-a-kind intent. Java is an object-orientated programming (OOPS) or dependent programming languages like C++ or C, while JavaScript is a client-faceted language.

 

Question 6.  Differentiate between the terms’ undefined and ‘not defined in JavaScript.

Answer. In JavaScript, if anyone wants to use such a variable that does not exist and has not been declared, JavaScript will show an error, the variable name is not defined, and the script will stop performing further. But when a type of undeclared variable is used, then it will resume undefined. Before we start a more in-depth discussion, let us understand the difference between declaration and definition.

Var x is a declaration because you have not defined its holding value but declared its existence and the need to allocate memory.

var x; // declaring x

console.log(x); //output: undefined

 

 

 

 

Var x = one is considered both the declaration and definition (we can also say that we are performing initialization). The declaration and assignment of the value in the string of the variable x takes place. In JavaScript, each variable declaration and function declaration results in a greater than its current declaration. The higher part of the range, then the term is called hoisting. A declared but not defined variable resulted in undefined when we try to process it.

var x; // Declaration

if(typeof x === ‘undefined’) // Will return true

 

 

 

 

 

When we try to access the variable that is neither defined nor declared variable, it is not defined.

console.log(y);

// Output: ReferenceError: y is not defined

 

 

 

 

Question 7. When should one use arrow functions in ES6?

Answer. Following thumb, rules are used for arrow functions in ES6.

  • Use “class” for object contractor.
  • Use “function” in the prototype object properties.
  • Use “arrow functions” all over the remaining places.

Question 8. Differentiate between “Object.freeze()” and “const”

  1. Object.freeze()” and “const” are two totally individual things.

let person = {

name: “Leonardo”

};

let animal = {

species: “snake”

};

Object.freeze(person);

person.name = “Lima”; //TypeError: Cannot assign to read only property ‘name’ of object

console.log(person);

 

 

  •    Const applies to references “variables,” creating an immutable link, which means you cannot allocate a new value to it.

 

 

 

 

 

 

 

 

 

  • Object Freeze () deals with the value or the value of the thing; it makes the object immutable; that is, its properties cannot change.

const person = {

name: “Leonardo”

};

let animal = {

species: “snake”

};

person = animal; // ERROR “person” is read-only

 

 

 

 

 

 

 

 

 

Questions 9. Why are => used almost all around?

Answer. Following are the features because of which => are used frequently:

  • Safety of the scope: If you use arrow functions in order, you can use the same object as the basis. If a standard callback function and multiple arrow functions are mixed, it is possible to exceed the scope of
  • Firmness: Reading and writing of arrow functions are more straightforward as compared to others.
  • Clarity: When almost everything is an arrow function, it will immediately highlight any standard procedure
  •  To determine the scope. Developers can always look up the following higher function declaration to find out what the object is.

Question 10. When is it required to use generators in ES6?

Answer. The generator has two simple features:

  • you can select to leap out of an element and permit outer code to decide while to leap returned into the function.
  •  It may be performed by the manipulation of an asynchronous call outdoor of your code.

The most vital function in generators is to get the subsequent value when required, now no longer all of the values at once. And in a few conditions, it may be very appropriate.

 

 

 

 

 

 

Question 12. What is a callback function?

 

 

 

Answer. A callback function referred the procedure to another part as a dispute and implemented after completing some operations. An example of simple callback function logging is to the console after the completion of operations.

 

 

 

 

 

 

 

 

 

 

 

Question 14. What type of data is supported by JavaScript?

  1. Following are the data types that JavaScript supports:
  • Null
  • Undefined
  • Number
  • Boolean
  • Object
  • Symbol
  • String

Question 15. What is a call back in JavaScript?

Answer. A callback is a simple JavaScript function that is passed to the method as an argument or option. This function is executed after another function is executed, hence the name “callback.” In JavaScript, functions are objects, so functions can function as parameters and can be returned by other functions.

Question 16. What is closure in JavaScript?

Answer. Whenever a variable referred outside the existing scope is accessed from the internal area, a closure is created. It allows you to access the content of the external function from the inner part. In JavaScript, a closure is created every time a position is created. With closures, you need to define a function into another process and make it available.

Question 17. Mention the rules that should be following while naming the variables?

Answer. JavaScript keywords should not be used as variable names. For example, the logical name or the cut variable name is invalid. JavaScript variable names cannot start with numbers (0-9). It must begin with a letter. For example, 123name is not a valid variable name, while name123 or _123name are valid. Naming JavaScript variable is a sensitive case. For example, test and test are two distinct variables.

Question 18. What is the use of Typeof Operator?

Answer. The type of operator is applied to obtain the data type of its operand. Operands can be text or data structures, including functions, variables, or objects. Although a unary operator is kept earlier, its only operand can be of any kind; its value is a string specifying the type of data in the operand.

 

 

Question 19. How can a cookie be created in JavaScript?

document.cookie = “key1 = value1; key2 = value2; expires = date”;

 

Answer. The most straightforward approach for a cookie creation is to allocate a string value to the [remote] object, as shown below:

 

Question 20. How can a cookie read in JavaScript?

Answer. Reading a cookie is as easy as writing it due to the value of the [deleted] object is a cookie. This way, you can implement the string if you try to access the cookie.

  • The [deleted] line contains a list of name=value pairs, separated by semicolons, where the name is the cookie’s name, and the value is its string value.
  • You can use the string split() function to split a string into keys and values.

Question 21. Explain various ways to access HTML in JavaScript code?

Answer. HTML can be accessed in JavaScript in the following way:

  • getElementById(‘idname’): Retrieve elements based on the name ID of the element.
  • getElementsByTagName (‘tagname’): Retrieve all elements with the specified tag name.
  • getElementsByClass(‘classname’): Retrieve all elements with the specified class name.
  • querySelector(): This function accepts a CSS style selector and returns the first designated element.

Question 22. How can a JavaScript code be involved in accessing an HTML file?

Answer. Following are how JavaScript code gets applied in accessing an HTML file:

Inline functions:

  • Inline function: These are JavaScript functions that are assigned to variables created at that time. You can distinguish between inline functions and anonymous functions because inline functions are assigned to a variable and can be reused very easily.
  • Internal and External Function: You can embed the script in the page you are working on or put it in a separate file, which you can access when you need it. It is the difference between internal scripts and external scripts.

Question 23. What did the term Typed language mean in JavaSript?

Answer. In typed languages, values ​​are associated with values, not variables. Therefore, it can have two types:

  • Dynamic: In this case, a variable can contain multiple types; just like in JS, the variable can be a number or a character.
  • Static: In this case, a variable can only hold one style because the string variable declared in Java can only accept one character set and not any other types.

Question 24. Differentiate between operators’ ==’ and ‘===’?

Answer: The essential difference between the “==” and “===” operators is that they compare variables in advance and correct the types. Suppose a number can be compared with a string having numeric literals. In that case, == allows you to do this, but === does not let you do so because it evaluates not only the value but also the type of the two variables, unless both variables are of the same kind, “===” returns false, and “==” returns true.

Question 25. Differentiate between a document and a window in JavaScript?

Answer. A JavaScript window refers to a global object that contains history, functions, variables, and location. In contrast, the document located at the bottom of the window views as a property of the JavaScript window.

Question 26. Differentiate between inner HTML and inner Text in JavaScript?

Answer. 

  • InnerHTML: If an HTML tag is found in the string, the tag is displayed.
  • InnerText: If found in the series, it will not render
  • the HTML markup.

Question 27. What are the consequences of actual private creation in JavaScript?

Answer. One of the disadvantages of creating accurate private methods in JavaScript is that it has very inefficient memory because the new copy of the system is designed for each case.

Each instance variable emp1, emp2, emp3 has its copy of the private raise method, as shown below. Therefore, if it is not necessary, please do not choose a unique method as a recommendation.

 

 

Question 28. Differentiate between an Anonymous and a Named function.

 

Answer. To differentiate between an Anonymous and a Named function, you can consider the following example.

 

var foo = function() { // anonymous function assigned to variable foo

// ..

};

 

var x = function bar(){ // named function (bar) assigned to variable x

// ..

};

 

foo(); // actual function execution

x();

 

 

 

 

 

 

 

Question 29. What does the term closure mean in JavaScript? 

Answer. The word “closure” is a combination of a particular function and the lexical atmosphere in which the process is declared. The term “lexical” refers to the lexical scope that uses the location of the declared variable in the source code to determine where the variable is available. A closure is a function that refers to an external (additional) function variable, that is, a scoped string, even after the outer function returns.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *