HARDEST JavaScript Interview Question Ever! Part 1
Q29. What is the difference between null & undefined?
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.
Q6. What are the advantages of JavaScript?
Following are the advantages of using JavaScript −
Q11: Explain what is hoisting in Javascript
Hoisting is the concept in which Javascript, by default, moves all declarations to the top of the current scope. As such, a variable can be used before it has been declared.
Note that Javascript only hoists declarations and not initializations.
Q8. How can you create an Array in JavaScript?
You can define arrays using the array literal as follows-
6. How do you calculate Fibonacci numbers in JavaScript?
Creating Fibonacci numbers is a very popular question for programmers. Try to answer it correctly with an efficient code example.
Example: “Fibonacci number sequence is a numbers sequence where each value is the sum of the previous two, starting with 0 and 1. The first seven values are 0, 1, 1, 2, 3, 5, 8. This JavaScript function will return Fibonacci numbers sequence up to a given numbers of terms.”
// ask for input from the user const number = parseInt(prompt(Enter the no. of terms: )); let n1 = 0, n2 = 1, nextNumber; console.log(Fibonacci Sequence:); for (let i = 1; i <= number; i++) { console.log(n1); nextTerm = n1 + n2; n1 = n2; n2 = nextNumber; }
Q37. What do you mean by Imports and Exports?
Exports and Imports specially assist us in writing modular JavaScript code. Using these, we can easily split our code into various files. Imports enables us taking only particular variables or procedures of a file. We can simply import variables or methods that are exported by a module. Following is the example for more details.
Q25. What are the ways to define a variable in JavaScript?
The three possible ways of defining a variable in JavaScript are: