Skip to content

Category: Questions

Return no element from `Array.flatMap()` by if condition

I have this code: The above code used a ternary operator of condition ? exprIfTrue : exprIfFalse. Currently I’m returning empty objects of { } in the case of exprIfFalse. How can I return nothing in the case of exprIfFalse? I mean, I want absolutely nothing. I mean no array element. Answer Why cant you …

Calculate Value from JS Promise

I have assigned a callback function to a variable. The function then returns a promise stating it is fulfilled and the value. I want to be able to return the value and use it to perform a mathematical calculation. Javascript code: In the console I get the below output. Answer Assuming this is the interface yo…

Why I can not call method of WebComponent?

I wonder why I cannot call a method defined in web-component if I attached this component via .append instead of using tag name inside the template. Below I am providing few examples. One is not working(throwing an error). I wonder why this first example is throwing this error. Example 1 In this example, I am…