Hi Guys Good Day and a Happy New Year 🎆🎆🎆!
This is a long one, so bear with me for a second or an hour. In every answer for every question there's an arrow up ↑ link that lets you go back to the List of Questions so that you don't waste time scrolling up and down.
The Questions
- 1. What's the difference between
undefinedandnull? - 2. What does the && operator do?
- 3. What does the || operator do?
- 4. Is using the + or unary plus operator the fastest way in converting a string to a number?
- 5. What is the DOM?
- 6. What is Event Propagation?
- 7. What's Event Bubbling?
- 8. What's Event Capturing?
- 9. What's the difference between
event.preventDefault()andevent.stopPropagation()methods? - 10. How to know if the
event.preventDefault()method was used in an element? - 11. Why does this code obj.someprop.x throw an error?
- 12. What is
event.target? - 13. What is
event.currentTarget? - 14. What's the difference between
==and===? - 15. Why does it return false when comparing two similar objects in JavaScript?
- 16. What does the
!!operator do? - 17. How to evaluate multiple expressions in one line?
- 18. What is Hoisting?
- 19. What is Scope?
- 20. What are Closures?
- 21. What are the falsy values in JavaScript?
- 22. How to check if a value is falsy?
- 23. What does
"use strict"do? - 24. What's the value of
thisin JavaScript? - 25. What is the
prototypeof an object? - 26. What is an IIFE, what is the use of it?
- 27. What is the use
Function.prototype.applymethod? - 28. What is the use
Function.prototype.callmethod? - 29. What's the difference between
Function.prototype.applyandFunction.prototype.call? - 30. What is the usage of
Function.prototype.bind? - 31. What is Functional Programming and what are the features of JavaScript that makes it a candidate as a functional language?
- 32. What are Higher Order Functions?
- 33. Why are functions called First-class Objects?
- 34. Implement the
Array.prototype.mapmethod by hand. - 35. Implement the
Array.prototype.filtermethod by hand. - 36. Implement the
Array.prototype.reducemethod by hand. - 37. What is the
argumentsobject? - 38. How to create an object without a prototype?
- 39. Why does
bin this code become a global variable when you call this function? - 40. What is ECMAScript?
- 41. What are the new features in ES6 or ECMAScript 2015?
- 42. What's the difference between
var,letandconstkeywords? - 43. What are Arrow functions?
- 44. What are Classes?
- 45. What are Template Literals?
- 46. What is Object Destructuring?
- 47. What are
ES6 Modules? - 48. What is the
Setobject and how does it work? - 49. What is a Callback function?
- 50. What are Promises?
- 51. What is async/await and How does it work?
- 52. What's the difference between Spread operator and Rest operator?
- 53. What are Default Parameters?
- 54. What are Wrapper Objects?
- 55. What is the difference between Implicit and Explicit Coercion?
- 56. What is
NaN? and How to check if a value isNaN? - 57. How to check if a value is an Array?
- 58. How to check if a number is even without using the
%or modulo operator? - 59. How to check if a certain property exists in an object?
- 60. What is AJAX?
- 61. What are the ways of making objects in JavaScript?
- 62. What's the difference between
Object.sealandObject.freezemethods? - 63. What's the difference between the
inoperator and thehasOwnPropertymethod in objects? - 64. What are the ways to deal with Asynchronous Code in JavasScript?
- 65. What's the difference between a function expression and function declaration?
- 66. How many ways can a function be invoked?
- 67. What is memoization and what's the use it?
- 68. Implement a memoization helper function.
- 69. Why does
typeof nullreturnobject? How to check if a value isnull? - 70. What does the
newkeyword do?
1. What's the difference between undefined and null?.
↑ Before understanding the differences between undefined and null we must understand the similarities between them.
- They belong to JavaScript's 7 primitive types.
let primitiveTypes = ['string','number','null','undefined','boolean','symbol', 'bigint'];
- They are falsy values. Values that evaluated to false when converting it to boolean using
Boolean(value)or!!value.
console.log(!!null); //logs false
console.log(!!undefined); //logs false
console.log(Boolean(null)); //logs false
console.log(Boolean(undefined)); //logs false
Ok, let's talk about the differences.
-
undefinedis the default value of a variable that has not been assigned a specific value. Or a function that has no explicit return value ex.console.log(1). Or a property that does not exist in an object. The JavaScript engine does this for us the assigning ofundefinedvalue.
let _thisIsUndefined;
const doNothing = () => {};
const someObj = {
a : "ay",
b : "bee",
c : "si"
};
console.log(_thisIsUndefined); //logs undefined
console.log(doNothing()); //logs undefined
console.log(someObj["d"]); //logs undefined
-
nullis "a value that represents no value".nullis value that has been explicitly defined to a variable. In this example we get a value ofnullwhen thefs.readFilemethod does not throw an error.
fs.readFile('path/to/file', (e,data) => {
console.log(e); //it logs null when no error occurred
if(e){
console.log(e);
}
console.log(data);
});