Chakram etc., more and more QA’s are now moving to a JS stack.
This is an example of explicit coercion –
let a = '42'; let b = Number(a); console.log(a); //string console.log(b); //this is a Number
In case of implicit coercion,
let a = '42'; let b = a*1 // here a is implicitly coerced to Number console.log(a); console.log(b);
A variable name has to be unique within the same scope. A scope can be nested inside another scope. If one scope is nested inside another, code inside the innermost scope can access variables from either scope.
- Strict comparison (e.g., ===) checks for value equality without allowing coercion
- Abstract comparison (e.g. ==) checks for value equality with coercion allowed.
Some simple equality rules:
- If either value (aka side) in a comparison could be the
- If either value in a comparison could be of these specific values (
— empty array), avoid
- In all other cases, you’re safe to use
==. Not only is it safe, but in many cases it simplifies your code in a way that improves readability.
What is a callback function with a sample example.
Ans : A
callback function is a function that is passed to another function as an argument and is executed after some operation is performed.
What is the use of
undefined. They are intended to mean different things:
- Something hasn’t been initialized :
- Something is currently unavailable:
undefined means a variable has been been declared but has not yet been assigned a value –
null on the other hand is an assignment value. It can be assigned to a variable as a representation of no value:
So, as you see, there is an obvious difference between these two.
undefined in itself is a type while
null is an object.
What is the difference between
const. There are subtle but powerful differences between these three, and the major difference is in scoping.
var variables are function scoped, if defined inside a function. If not, they’re globally scoped.
const variable are block scoped – which mean they are available inside the block that they’re defined.