JS Flashcards
Difference between “ == “ and “ === “ operators.
Both are comparison operators. The difference between both the operators is that,“==” is used to compare values whereas, “ === “ is used to compare both value and types.
Explain Hoisting in javascript
Hoisting is a default behaviour of javascript where all the variable and function declarations are moved on top.
What are the different data types present in javascript?
Primitive data types can store only a single value. To store multiple and complex values, non-primitive data types are used.
Primitive: string, Boolean, Undefined, Null
Non-Primitive: object
To know the type of a JavaScript variable, we can use the typeof operator
Explain Implicit Type Coercion in javascript
Implicit type coercion in javascript is automatic conversion of value from one data type to another. It takes place when the operands of an expression are of different data types.
var x = 3; var y = "3"; x + y // Returns "33"
Is javascript a statically typed or a dynamically typed language?
JavaScript is a dynamically typed language. In a dynamically typed language, the type of a variable is checked during run-time in contrast to statically typed language, where the type of a variable is checked during compile-time.
What is NaN property in JavaScript?
NaN property represents “Not-a-Number” value. It indicates a value which is not a legal number.
Explain call(), apply() and, bind() methods.
call()
It’s a predefined method in javascript.
This method invokes a method (function) by specifying the owner object.
apply()
The apply method is similar to the call() method. The only difference is that,
call() method takes arguments separately whereas, apply() method takes arguments as an array.
bind()
This method returns a new function, where the value of “this” keyword will be bound to the owner object, which is provided as a parameter.
Example with arguments:
Explain Scope
Scope in JS, determines the accessibility of variables and functions at various parts in one’s code.
In general terms, the scope will let us know at a given part of code, what are the variables and functions that we can or cannot access.
There are three types of scopes in JS:
Global Scope
Local or Function Scope
Block Scope
What are callbacks?
A callback is a function that will be executed after another function gets executed.
What is recursion in a programming language?
recursion is a technique to iterate over an operation by having a function call itself repeatedly until it arrives at a result.
What is the use of a constructor function in javascript?
Constructor functions are used to create objects in javascript.
When do we use constructor functions?
If we want to create multiple objects having similar properties and methods, constructor functions are used.
What is DOM?
DOM stands for Document Object Model.
DOM is a programming interface for HTML and XML documents.
When the browser tries to render a HTML document, it creates an object based on the HTML document called DOM. Using this DOM, we can manipulate or change various elements inside the HTML document.