Posts by Luiz Felipe • 32,886 points
746 posts
-
4
votes2
answers470
viewsA: How to apply mock in "new date()" using Jest?
The Date is a global object in Javascript. This means that it is a property of window (in the browser), of global (in Node.js) or globalThis (in browsers modern and recent versions of Node.js).…
-
5
votes1
answer92
viewsA: Is it possible to see the image load progress in js?
The native elements <img>, interface HTMLImageElement, although it does (inherited from HTMLElement) event properties like onload, do not have native means to merge progress. You can then use…
-
5
votes1
answer375
viewsA: How to cancel/interrupt a request made with Axios?
As the interface name says, a promise cannot be broken. So, by itself, Promises are not cancellable in Javascript. However, the Axios offers a request cancellation mechanism. Basically, you need to…
-
13
votes2
answers246
viewsA: What does "!!~" mean in Javascript?
There are three operators working together, two of them being the logical negation operator (Logic NOT — !) and the third, the operator bitwise of denial (bitwise NOT — ~). In that case, the first…
-
2
votes1
answer36
viewsA: I need to make a comparison using Javascript
One option is to create a variable that keeps the older person’s age (you can use one object if you have to store more information about the person). Thus, we start the value as 0 and, if the person…
javascriptanswered Luiz Felipe 32,886 -
1
votes1
answer45
viewsA: Doubt about exceptions and Try/catch blocks
There is no right or wrong in this case. It depends on your need. In relation to language, both are correct. The difference in output is due to the fact that when some exception is released in…
-
0
votes1
answer23
viewsA: Doubt between performing clearfix using an element in the DOM or a pseudo-element
The difference is, when using a <br> (or any other element to make the clearfix), you are inserting an element into the DOM. By using the pseudo-selector ::after, you insert a pseudo-element…
-
2
votes1
answer57
viewsA: After reloading, the jQuery system does not work
The problem is that you are attaching the Listener of event in the <div class="click">ops</div>, that will be removed from the page when you use the method html. Thus, your Listener…
-
1
votes3
answers464
viewsA: Identify amount of upper and lower case letters in a string
According to the documentation of any: Returns True if any element of iterable is true. If iterable is empty, returns False. As this function returns a boolean, it makes no sense to compare them as…
-
3
votes2
answers99
viewsA: Program a test to check for libraries in the "package.json" type "@types/..." that are in the wrong place. Is it possible?
If you have a script test in his package.json, can create another call pretest, which will always be run automatically before of test, or posttest, to be executed afterward of test (also…
-
8
votes2
answers1355
viewsQ: What is SSL Pinning?
I was recently watching a video that briefly mentioned the term "SSL Pinning" to describe a measure (understood by me as security) to establish a more secure and probably encrypted communication…
-
1
votes1
answer97
viewsQ: What is Ienumerable.Getenumerator in C#?
I was reading this documentation and I came across the following piece of code within a class that implements IEnumerable: // Implementation for the GetEnumerator method. IEnumerator…
-
3
votes2
answers170
viewsA: Convert a string in monetary format to number and subtract 90%
The problem lies in its function getMoney, that is not converting the numeric string (in Brazilian format) correctly. More specifically, the error is due to this regular expression: /[\D]+/g She…
-
5
votes2
answers241
viewsA: Is there a difference between Number and parseFloat?
The difference is subtle that can be noticed in the documentation parseFloat: The parseFloat Function parses an argument (Converting it to a string first if needed) and Returns a floating point…
-
3
votes2
answers188
viewsA: Locate the index of the highest and lowest value of an array
You can use a for simple, storing the indices of the highest and lowest number and modifying them if necessary. This way, you only need to scan the array once. Something like that: function…
-
3
votes1
answer32
viewsA: How to access the element that activated the event without using jQuery?
Use the mechanism of closures of language As in "pure" Javascript we need to iterate on the NodeList (returned by methods such as querySelectorAll) to add each Listener event, we can make use of the…
-
3
votes1
answer35
viewsA: Passing dictionaries key as parameter in integrated function
You can use the function map to map the list with the dictionaries in a list with only the ages and then calculate the average. import statistics as stt pessoas = [{"Nome": "Joana", "Idade": 14},…
-
3
votes1
answer20
viewsA: Create an on-screen alert when a specific time is reached
Simply calculate the difference (in milliseconds) between the current date and the date on which you want to issue the alert, passing this interval to the second argument of the setTimeout. Since…
javascriptanswered Luiz Felipe 32,886 -
6
votes2
answers64
viewsA: How to mount a number 1 pyramid of 20 consecutive lines?
One option that I consider a little more appropriate for this sort of thing is to use the method String.prototype.repeat, repeating a string N times. for (let i = 1; i <= 10; i++) {…
-
1
votes1
answer34
viewsA: How to make a menu appear and hide it?
First of all, there is no display: show in the CSS. As pointed out in comments, the ideal in this case is to use display: block as opposite at the display: none, in order to display the menu. The…
-
3
votes1
answer41
viewsA: Omit extended typescript typing
One option is to simply create separate types. One for dice to be stored in the model (as ModelData) and the other which, in fact, represents the model, formed from the intersection of ModelData and…
-
1
votes1
answer138
viewsA: Place the values of two inputs inside an array in React?
The first point is that you need some way to distinguish the two <input>s you are using, so as to insert them in the correct positions of the array. Once you’ve done that, just position them…
-
4
votes1
answer65
viewsA: Why is my route in React /#/?
Why are you using the HashRouter, using location.hash to determine the page the user will see. This part of the URL is called hash. You can use the BrowserRouter to have a path "normal" managed by…
-
1
votes2
answers31
viewsA: Error trying to access form fields
The problem lies in this part of the code: var form = document.querySelector("#form"); var filme = form.filme.value; var genero = form.genero.value; var dvd = form.dvd.value; var dimas =…
-
5
votes3
answers196
viewsQ: What causes my component to be rendered again in React?
Very commonly I see talk that a component of React will be re-rendered because of a prop, state, value of context altered, etc.. What are the factors that actually influence the re-rendering of a…
-
4
votes1
answer127
viewsQ: What are Javascript property descriptors and attributes and how do they work?
Eventually I read, mainly in more advanced content about objects in Javascript, the terms "proprietary descriptors" and "property attributes". I believe they are related concepts. What they are and…
-
6
votes1
answer127
viewsA: What are Javascript property descriptors and attributes and how do they work?
Property descriptor It is known that Javascript is a language that does extensive use of objects. To make some of the language features work, it is necessary to associate some information to each of…
-
4
votes1
answer166
viewsA: Math.Running defining minimum and maximum values other than 0
This is happening because you are not passing numerical values, but yes strings that in some cases (given the coercive behavior of Javascript) will be converted, but in others, not. Thus, as the…
-
0
votes2
answers45
viewsA: How do I increase a CSS property using Js?
You can create a variable to keep information of how many pixels the element should be away (by property left) and, with each click on the button, change this property and compute the new left using…
-
0
votes1
answer38
viewsA: Problem with typescript paths
According to the documentation of plugin eslint-plugin-import, the rule import/no-unresolved: Ensures an Imported module can be resolved to a module on the local filesystem, as defined by standard…
-
3
votes1
answer113
viewsQ: Is there any difference between the terms "call", "invoke" or "apply" a function?
I commonly read the term "invoke" or "call for" a function to refer to the action of executing that function. But I may also read the term "apply". In my view, all three of these terms have the same…
-
6
votes3
answers239
viewsA: Ordering arrays with Bubble Sort
If you want to remove the "intermediate function" bubbleSort, just "relocate" the loop for that is in her body into the for main. Thus: function bubbleSort(originalArray) { const bubble =…
-
5
votes1
answer158
viewsQ: In terms of user experience, is it impactful to remove accents and special characters from a URL?
I wonder if there is a reason to remove special characters from a URL. For example, the URL below (here from Sopt): en.stackoverflow.com/questions/27177/o-que-is-callback It has, of course, a…
-
1
votes1
answer43
viewsA: How to use special characters to select an element using jQuery?
This happens because you cannot put any character as selector. A documentation jQuery highlights these characters as "reserved" for selectors: ! "#$%&'()*+,./:;<=>?@[\]^`{|}~ So when you…
-
10
votes1
answer941
viewsA: What is the difference between Object.assign and spread Operator?
There are some subtle differences: Difference in the definition of properties The first of these is that Object.assign uses internal operation [[Set]] to define properties. Scattering notation…
-
8
votes3
answers300
viewsA: How to perform a condition in the array to verify that multiple elements exist at the same time?
Using the method includes, you can only verify if an element exists at a time, since only the first argument can be used for that purpose. See documentation to learn more. If you want to check if…
javascriptanswered Luiz Felipe 32,886 -
4
votes1
answer69
viewsQ: Why are different types of quotes used in places as error messages?
Eventually I see different quotes (one type of quotes to "open" and another to "close") some message, mainly in error messages. Take, for example, an error message issued by Ruby when evaluating a…
language-independentasked Luiz Felipe 32,886 -
2
votes2
answers124
viewsA: Doubt in array method each_with_index
You are printing the "account" itself (and not the product result) because the terms are interpolated within a string: puts "#{index} * #{value}" It will print, for each iteration, the index value,…
-
3
votes1
answer43
viewsA: Problem with running order of endpoints in Express with conflicting paths
This is not a bug. It is working as the code "sent". Remember that code is nothing more than a series of instructions to a computer. The point is that Express runs the handlers of each route…
-
4
votes1
answer125
viewsA: Differences between defining object methods using Arrow Function and Function Expression
"Methods" such as Arrow functions The difference is that in the first case, you are using a Arrow Function to define the method. See this question and the documentation to learn more about this type…
-
8
votes1
answer147
viewsA: How to use a predefined interpolation in Javascript
Javascript does not have templates natively. Do not confuse strings template with a "real template", which can be "evaluated" later - as the function format python makes. As strings template of…
-
2
votes1
answer40
viewsA: My function returns true or false. I made the code, but I think it could be shorter with native js methods
The every is not the most ideal in this case, it is most indicated when you want to test if all elements of an array validate some predicate. In that case a bow for with a map to know how many years…
javascriptanswered Luiz Felipe 32,886 -
2
votes1
answer209
viewsA: When calling an asynchronous function, is it also necessary to note the calling function as "async"?
In Javascript, it doesn’t matter if you’re using callbacks, Promises or asynchronous functions (which are basically syntactic sugar for the promise API), asynchronous is like a "plague". This means…
-
2
votes1
answer33
viewsA: Tds do not use full table width
Simply apply the width and the height in the table itself, without using the display: block in it: table { border-collapse: collapse; height: 80vh; width: 95vw; } tr { text-align: center; } table,…
-
6
votes2
answers186
viewsA: Doubt about Number.isInteger() in JS. Number is an object or function?
Number would be a function or object? TL;DR: It is a constructor function (and therefore an object too, learn more in the documentation and in the question Why Arrays and Functions are Objects?).…
-
1
votes1
answer39
viewsA: How to disable Git indications (Gutter) of modified lines in Vscode?
This is an indicator of Git status - or any supported version control software. In this place, it’s called Gutter, which is the left-hand display of the code lines. To disable, you can use the…
visual-studio-codeanswered Luiz Felipe 32,886 -
7
votes1
answer111
viewsA: Set does not remove duplicate objects
Consonant with the language specification (in free translation): Objects Set are collections of values of the Ecmascript language. A distinct value can occur only once as an element of a collection…
-
1
votes1
answer40
viewsA: How to get a file name
The estate files of a <input> of the kind file returns a FileList, which is an object similar to an array. It is therefore a list of files (instances of File). To get the file name of an…
javascriptanswered Luiz Felipe 32,886 -
3
votes3
answers133
viewsA: Is it possible to leave the delay argument of the dynamic setInterval?
The interval is scheduled so that every X seconds the function passed will be executed as callback. Therefore, for each interval you create, the time between each "run" will be constant and cannot…
-
2
votes1
answer50
viewsA: How do these symbols (text Fragments) work in the "#:~:text=" URL?
This is a recent feature (possible from Chrome 81, for example) that allows you to create a link that also determines a position in a particular text present on the page, which will be highlighted.…