Posts by Cmte Cardeal • 5,299 points
158 posts
-
5
votes3
answers204
viewsQ: How to serialize and deserialize objects containing Bigint values in Javascript?
Let’s adopt any example code that contains a type value Bigint: const params = { largeNum: 54740991n } If I try to serialize you with JSON.stringify an error is returned: const params = { largeNum:…
-
3
votes3
answers109
viewsA: How to compare arrays ignoring the order of the elements in Jest?
Use a combination with the arrayContaining within the toEqual: const array = [{ name: 'Bob' }, { name: 'Alice' }] expect(array).toEqual( expect.arrayContaining([{ name: 'Alice' }, { name: 'Bob' }])…
-
6
votes3
answers153
viewsQ: What is the way to check and react to a change of state of an array using pure Javascript?
I’m studying about the pattern Observer where in an example done in Java it was demonstrated that an X class any called a specific method Y and this called methods updateof the observers, that is to…
-
5
votes3
answers153
viewsA: What is the way to check and react to a change of state of an array using pure Javascript?
Possible solution There is a way to call a function when method, which changes the state of that array, is called. Using the Object.defineProperty, where we could do something like extend the…
-
3
votes1
answer65
viewsQ: What is "Error cause" in Javascript?
It is common to have mistakes thrown and these errors have to be captured and treated in different ways, according to the context. I see (and use) the practice of creating custom classes of errors…
javascriptasked Cmte Cardeal 5,299 -
0
votes1
answer36
viewsA: How to map the value of 2 inputs in React?
The problem is in <Modal title={todo} content={value2}/>, it makes direct reference to the state of value2 in content={value2}, therefore any change in that state shall be reflected in Modal.…
-
4
votes2
answers71
viewsA: Is it possible to overload Javascript mathematical operators for objects?
The way you demonstrated (player - mass) will return to you NaN as an answer, because the - force conversion to number, which is not possible with objects. If both objects are "equal" in structure,…
-
2
votes1
answer37
viewsA: What is the Vscode configuration responsible for the check system (deselect in the case) the unused variables yet?
Based on this reply from Soen, you can change JSON by adding the following value to "editorUnnecessaryCode.border" within the workbench.colorCustomizations: "workbench.colorCustomizations": {…
visual-studio-codeanswered Cmte Cardeal 5,299 -
1
votes1
answer58
viewsA: How to stop playing a video from an iframe when closing modal?
There is a way to do this by just resetting the attribute src of iframe, and this will end the video playback. In your case, with the function in the following code snippet: window.onclick =…
-
2
votes1
answer28
viewsA: I am trying to make a program that shows the table that the user chooses, but is only compiling the first multiplication. (x * 1 = x)
Your mistake is here, calling the function pL: function mostra(frase) { document.write(frase); pL(); // esse chamada ativa a recursão infinita.... }; That call pL calls again the function mostra and…
-
3
votes1
answer74
viewsQ: Are "Empty" values within an array not eternal?
In this code snippet: let arr = []; arr[3] = null; The following excerpt arr[3] = null; makes the array size according to the value within the array annotation []. The forEach will be used to work…
-
2
votes2
answers6959
viewsA: What is the difference between npm and npx?
I will complement and highlight some things in relation to another answer... What is NPX? NPX is an NPM package runner that makes it really easy to install any type of node executable that would…
-
5
votes1
answer60
viewsQ: What is the relation of the "+" operator to the "valueOf()" method in Javascript?
I have a question about the operator +. In this answer on the operator, the following was said: The + can also play the role of a binary operator. In that case, operates on two values. In this…
-
1
votes2
answers41
viewsA: Why can’t I call a function by input type="Submit"?
Just by complementing the @fweydson response, you can keep your code as is, just add the code to prevent the form from being submitted as demonstrated in the other reply by adding the…
javascriptanswered Cmte Cardeal 5,299 -
3
votes2
answers45
viewsA: How to make a counter with javascript speed setting to simulate game time
By toggling the @Augustovasques response, we could use recursion and adopt some parameter (number) for the function to set a delay time and thus control the execution speed. Let’s assume the delays…
javascriptanswered Cmte Cardeal 5,299 -
3
votes1
answer89
viewsQ: Is it possible to apply or simulate immutability to an "object" of the Map type in Javascript?
For objects, we can leave it unchanged, so trying to re-assign a new value to a property, adding new properties, or removing properties is not possible. Of course, in case the object suffered…
-
1
votes1
answer29
viewsA: Error vuejs 'this. $delete is not a Function'
In a question from Soen, was said to use the Vuex state manager, the methods $delete and probablythe $set must not be accessible, which may explain the error message this.$delete is not a function.…
-
3
votes2
answers86
viewsQ: Why does Node.js accept value assignment with the "Undefined" identifier?
I was conducting a quiz on Node.js until I came across the following question: Which message will appear in the terminal for the following code executed by Node.js: Code (note that it runs outside…
-
3
votes2
answers86
viewsA: Why does Node.js accept value assignment with the "Undefined" identifier?
The answer is quite simple... The module wrapper Recalling... The undefined is a property of the object global, that is, it is a variable in the global scope. The initial value of undefined is the…
-
6
votes1
answer115
viewsQ: Why should we interrupt the Promises current in recursive functions in Javascript?
I will exemplify with codes. I have an asynchronous function called delay which receives a time in seconds and which returns a Promise. It serves to provide a waiting time in seconds: // padrão de 1…
-
1
votes2
answers59
viewsA: How to reload date after a Vuejs action
You can remove the element from the list dog after calling the API, using simple array methods. Within the method deleteDog: deleteDog(id) { api.delete("dog/" + id).then(() => { // localiza o…
-
6
votes1
answer336
viewsQ: What is BFF (Back-end For Front-end)?
This is a term that I have come across several times and I recently saw that this term was cited as a requirement for a job vacancy for a junior dev. I don’t know if that would be absurd, to demand…
-
2
votes1
answer72
viewsQ: How to convert a Promise-based function to callback in Javascript?
We can convert asynchronous functions that work with callback to work with Promises, as shown in the examples below: callback: const timeInMs = 1_000; function asyncCallback(timeMs, callback) {…
-
4
votes2
answers67
viewsA: What does the "jsx" prop do in Next.js' jsx <style?
This is the syntax of a standard library of Nextjs, this is called Styled JSX, and the fact that it is used <style jsx> is not to be confused with the tag itself <style> of HTML. What’s…
-
9
votes1
answer271
viewsQ: Why does "parseint(0.0000005)" return "5" in Javascript?
Again, Javascript shows me a show of horrors magic and this time I want to know why this unexpected behavior while using the parseInt. Why parseInt(0.0000005) returns 5 and not 0? How I get around…
-
3
votes1
answer64
viewsA: My subtraction calculus in Javascript is returning a "Nan"
It turns out that subtraction of values can do the parse both strings (valor and custo) following the format 0.00 (for example) or string that has integer format '0'. He can identify the . floating…
-
3
votes1
answer95
viewsQ: How to import content from a JSON within an ESM (Ecmascript modules) module in Node.js?
It is common for me to see online courses, articles and tutorials over the internet, Node.js codes that can import local JSON files into code to be manipulated, used, tested, etc... In these…
-
4
votes1
answer73
viewsQ: What is the purpose of the Promises Timers API on Node.js?
Recently, in the version V16.0.0 of Node.js, added the Promises Timers API, and from what I understand, it’s about alter the behavior of standard timers (setTimeout, setImmediate, etc...). These…
-
1
votes1
answer61
viewsA: Problems creating schema by Knex js
And I’m going to propose an answer that I can’t guarantee will work, but when I had the same problems, it solved for me. Knex presented problems every time I tried to create relationships in a Mysql…
-
1
votes2
answers694
viewsA: What are semantic messages in Git?
Use on Node.js Just adding the answer of Vinicius, for those who have interest in following the commit standardized using Node.js, there is a package in NPM called git-commit-msg-linter . This…
-
0
votes1
answer58
viewsA: Treatment of negative test cases with JEST
In your case, if you expect createUserService.execute launch a Error, you should use the await before the expect, That means telling Jest to expect an asynchronous function to be rejected (rejects)…
-
4
votes1
answer146
viewsQ: What is the difference between the "in" operator and the "hasOwnProperty" method in Javascript?
An unexpected behavior (at least for me) occurred with the following excerpt of code that I will demonstrate below: const str = new String('olá SOpt'); console.log('Usando "in"', 'length' in str);…
-
2
votes1
answer223
viewsA: How to style HTML5 calendar icon
OBS: The solution below does not work in the Firefox browser. Check for compatibility in other browsers for this solution. Tests have been done and worked on Google Chrome and Brave browsers.…
-
0
votes1
answer34
viewsA: How to make React return specific components depending on the state?
If you want to use the conditional rendering, do not insert blocks if within the code rendering the component. First that the way you did is incorrect and second because it is not good to insert…
-
1
votes1
answer216
viewsA: Property 'todos' is Missing in type '{ setTodos: (todos: Itodo[]) => void; key: string; text: string; }' but required in type 'Props'
Your code was a little difficult to test, but I think I found a possible solution. First, as I mentioned earlier in this answer, the type for a function setState is a…
-
1
votes1
answer26
viewsA: Render radio Buttons based on arrays
For what you implied based on the image, options is an array of size 1 containing another array of size 4. Serial something like: [[{id: 1, ...}, {id: 2, ...}, {id: 3, ...}, {id: 4, ...}]] Then you…
-
4
votes1
answer96
viewsQ: Is there anything similar to the Optional Chaining (optional chaining) of Javascript in PHP?
We know that in Javascript: The optional chaining (optional chaining operator) ?. allows the reading of the value of a property located internally in a chain of connected objects, without the…
-
1
votes1
answer193
viewsA: Mongodb - change object value within object array
Assuming that your users have a field of address as an array, let’s demonstrate the example case: users: { name: '...', age: 20, // ... address: [ { _id: '123', street: '...' // ... }, { _id: '456',…
-
5
votes1
answer91
viewsQ: What is Regexp Match Indices?
I recently found this package, which serves as a polyfill for a new Javascript feature. The proposal Regexp Match Indices was finalized recently, which means it will soon be part of the language. On…
-
1
votes1
answer120
viewsA: How to make two Scrollview on the same screen in React Native
First, I’m going to assign the style of container for a View that will contain all the code, to avoid throwing error (at least in my tests) and we will activate the scrollEnabled. How does it look:…
-
10
votes2
answers224
viewsQ: What is the underscore ( _ ) "inside" of a Javascript number?
I realized I can use underscores (_) between numeric literals in Javascript. For example: const testA = 1_000_000_000; console.log(testA); // => 1000000000 const testB = 1000000_0 + '_0_' + 1_0;…
-
3
votes1
answer170
viewsA: Problem typing first parameter of React setState
This happens because the setState is much more than a simple function that returns only a boolean. In the variables of useState, the second element (mudarExecucao) is a function of the type…
-
1
votes1
answer62
viewsA: How popular is an object loaded with populate in Mongoose?
You would have to use populate for multiple levels. In your case you can try to pass a contentious array of field rules to popular. An example for your case, let’s popular the field reforco and from…
-
1
votes1
answer45
viewsA: Is the use of the operator "and" in this code correct? Because it is not working
Apparently you want to make a query that results in AND for verification of senha and email, that is, the SQL query you expect would be algorithm of type: SELECT * FROM post WHERE email =…
-
2
votes1
answer32
viewsA: Loop to change text from a cell (A) when you click a button (B) located on the same row as the cell (A) in an HTML table
I know this response could be a comment, but I wanted to try to elaborate a clear explanation of the subject addressed... Your case is a serious scope problem because of var, it does not maintain…
-
3
votes1
answer169
viewsQ: What is the difference between "test" and "spec" in automated testing?
The question and doubts below address Node.js, Typescript and Javascript. I don’t know if the concepts below apply to other programming platforms/ languages. I am studying about automated tests (AT)…
-
2
votes2
answers76
viewsA: How to prevent a div with flex display shrinks the child elements?
Tried to use the min-width for both divs? This prevents the divs decrease below the limit and causes the scroll horizontal. See below: .container { width: 200px; height: 50px; background-color:…
-
4
votes2
answers65
viewsA: How to take more than one property in a Javascript object array using unstructuring
First of all, this here getCount([...objArr]) is irrelevant and redundant. Your role should receive only objArr, for it is already an array and that way getCount([...objArr]), the objArr within the…
javascriptanswered Cmte Cardeal 5,299 -
0
votes1
answer53
viewsA: How to replace the awesome font icon with Javascript
For some reason, this problem is being caused by the Font Awesome. He’s commenting on the line where the icon is i and putting an SVG in place. Behold: See the code not working: I removed the…
-
2
votes1
answer82
viewsA: Checkbox does not deselect in React Native
First, the attributes check and name do not exist in the component CheckBox, then we will not use them. We will only work with the following attributes: value, which will store a boolean value…