Most voted "javascript" questions
Use this tag when the question refers to some feature, information, or problem that relates exclusively to the Javascript language (not to be confused with JAVA). Javascript is an implementation of Ecmascript, a dynamically typed, object-oriented, prototypical-inherited language. It is used for client-side scripting, but can be run in desktop or server-side applications using tools such as Node.js.
Learn more…26,588 questions
Sort by count of
-
40
votes12
answers79762
viewsFormatting Brazilian currency in Javascript
I have the following variable: var atual = 600000.00 ; Here we have the value six hundred thousand in American standard, I would like when I print on the screen to look like this: 600.000,00 I’m…
javascriptasked 8 years ago Lennon S. Bueno 2,182 -
39
votes8
answers48548
viewsHow to pass parameters in function calls by reference in Javascript?
I recently asked the question Why should we use Anonymous functions with jQuery instead of the function directly? and along with the accepted answer came a second question: How to pass arguments to…
-
39
votes3
answers6437
viewsInaccurate result in broken numbers calculation
Problem Test there in the consoles of your browsers: 1067.11-1000 = 67.1099999999999 The right thing would be 67.11 Could someone explain this to me? And how do I fix it?…
-
38
votes4
answers66720
viewsWhat is the correct way to make a regular Javascript substitution for all occurrences found?
What is the correct way to make a regular Javascript substitution for all occurrences found? The way I do these days: var i = 0; while ((i = str.indexOf("_", i)) != -1) { str = str.replace("_", "…
-
38
votes8
answers14487
viewsHow to create a copy of an object in Javascript?
I have an object called cachorro and would like to create and store a copy of that object. As objects, vectors, functions and regular expressions are considered objects I cannot make a copy just by…
-
38
votes2
answers1727
viewsWhat is the function of the ~ (til) Javascript operator?
I tried to search for Google and SOEN, but I did not find any reference to the operator ~, I discovered that it exists because I was reading a book about Javascript and had an example using it, but…
-
38
votes3
answers5488
viewsHow to use the current value of a variable in a more internal function?
The following code "prints" 50 times the text "Message 50" in a textarea. for (var i = 0; i < 50; i++) { setTimeout(function() { textArea.value += 'Mensagem ' + i + '\n'; textArea.scrollTop =…
-
38
votes1
answer1300
viewsWhat does the && in between strings mean?
I found in a minified bootstrap file, the following: e=e&&e.replace(/.*(?=#[^\s]*$)/,"") The operator && seems to be being applied between two strings. What does that mean?…
javascriptasked 11 years ago Miguel Angelo 28,526 -
38
votes2
answers8746
viewsIs Javascript interpreted or compiled at runtime?
In this other question I asked the same thing, but in relation to Java. Now I ask about Javascript. As far as I know, historically Javascript has always been interpreted, but Google has changed that…
-
37
votes2
answers10986
viewsWhat is JSONP and how does it work?
What is JSONP, how to use and why to use JSONP instead of AJAX?
-
37
votes9
answers34793
viewsInput type="password" with password display eye
I need to put a <input type="password"> with that eye of the reveal password, but it has to work as follows: User clicks on the eye and when dropping hides the characters again. Follow an…
-
37
votes5
answers7326
viewsIs Javascript an Object-Oriented language?
Many say that it is not an object-oriented language, because it is not possible to define classes in it, until its version Ecmascript 5, but with the use of constructing functions and prototyping it…
-
37
votes3
answers439
viewsHow to get a similar behavior between the Garbage Collection of a Single-Page Application and a Multiple-Page Application?
I’ve been doing a lot of research on the web and in stackoverflow communities, and I’m getting to the point of believing that Spas take almost no advantage of the GC algorithm of current browsers.…
javascript memory memory-management single-page-application memory-leaksasked 7 years, 9 months ago LeonanCarvalho 3,527 -
36
votes4
answers58476
viewsIF, ELSE IF, ELSE or IF IF IF. When to use, what’s the difference?
It’s a very basic question, but it intrigues me a lot. See the code below: var bola = "redonda"; if(bola == "comestivel") return comer(); if(bola == "liquida") return beber(); if(bola == "redonda")…
-
36
votes5
answers4312
viewsWhat does Nan mean in Javascript?
When we have an error in the sum of a number with Javascript, it is returned NaN. Example: parseInt('a') + 3; //NaN What does it mean NaN?…
-
36
votes3
answers1249
viewsWhy can I create two functions with the same Javascript signature?
I’m having doubts about a certain issue in Javascript, suppose the following scenario below: function teste() { console.log("teste1"); } function teste() { console.log("teste2"); } teste(); In that…
javascriptasked 7 years, 11 months ago Jeferson Almeida 3,076 -
34
votes7
answers87300
viewsHow to validate with regex a string containing only letters, whitespace and accented letters?
I’m looking to validate one input text for full name in order to accept only letters, blank spaces and accented letters. Valid formats: Leandro Moreira leandro moreira Kézia Maria kezia maria Cabaço…
-
34
votes9
answers166445
viewsHow to hide/show a div in HTML?
How do I make a Javascript that shows/hides a div in HTML? I tried like: function Mudarestado(divid) { var disp = document.getElementById(divid).style.display; disp = "none; // (ou disp = "block") }…
-
34
votes1
answer36730
viewsJavascript: Differences between import and require
I know that import and require are used in Javascript to import functions or objects from third parties. Code snippets like: import Library from 'some-library'; or const Library =…
-
33
votes4
answers2243
viewsAlternative to CPF (Foreign Users)
I have a site where we control users by number of CPF, I believe it is the best way because it is a given single, that everyone knows and is checavel. However the client now has foreign users who do…
-
33
votes3
answers21328
viewsCreate HTML element with Javascript (appendchild vs innerHTML)
Recently I’m creating a lot of HTML dynamically. Example var table = document.createElement('table'); table.style = 'width:500px;border:1px solid #CCC;'; var tbody = document.createElement('tbody');…
-
33
votes5
answers1273
viewsWhy Nan Nan == 0?
Check out these tests I did on the browser console: NaN / NaN NaN NaN * NaN NaN typeof NaN "number" NaN ** NaN NaN NaN ^ NaN 0 Because exactly that happens?…
javascriptasked 7 years, 8 months ago Artur Trapp 5,175 -
32
votes7
answers58283
viewsRegular expression for e-mail validation
I am trying to create a regular expression to validate any e-mail, I wrote the expression below, but it is not working as expected: var parse_email = /^[a-z0-9.]+@[a-z0-9]+\.[a-z]+\.([a-z]+)?$/i;…
-
32
votes5
answers5370
viewsHow to apply ! CSS import via jQuery?
I’m trying to apply style to my element and define its importance in this way: $('div').css('height','50px!important'); But it doesn’t work, which would be the right way?…
-
32
votes5
answers32771
viewsHow to calculate the age of a person with JS, from the date of birth?
How can I calculate a person’s age in Javascript from the date of birth? I tried something like: function idade(dia, mes, ano) { return new Date().getFullYear() - ano; } idade(11, 12, 1980); // 33…
javascriptasked 11 years ago Cabeção 1,799 -
32
votes5
answers1927
viewsWhy is multiplication faster than division?
Bit brushing question, but I was reading an article about javascript in which says that division is slower than multiplications. And for example, I would recommend changing the code below : var…
javascript mathematics performance optimizing characteristic-languageasked 10 years, 10 months ago Guilherme de Jesus Santos 6,566 -
32
votes1
answer7672
viewsHow does asynchronous programming work in Javascript?
As far as I know, asynchronous programming in C#, for example, uses the idea of threads. The tasks to be performed can be divided into threads and then run in parallel. I always imagined that…
-
32
votes2
answers55629
viewsCORS - No 'Access-Control-Allow-Origin' header is present on the requested Resource
Good evening, I’m trying to access a server from my local machine and I’m getting this answer: No 'Access-Control-Allow-Origin' header is present on the requested Resource. Origin 'http://localhost'…
-
32
votes1
answer3647
viewsWhat is shadow DOM?
When I was reading about some Javascript frameworks, for example the React, I read the expression a few times shadow gift in some articles. It even seems that it is possible, in Chrome console…
-
32
votes3
answers13710
viewsWhat is a Polyfill?
I’ve seen that term Polyfill being used several times when it comes to a new function that is not available in older versions of certain languages and the like. But after all, Polyfill is simply…
-
31
votes5
answers14927
viewsHow to not allow a character to be typed in the textbox, with Javascript/jQuery?
I have a Textbox: <input type="text" name="indice" class="number"> I wanted that when a person typed a comma in this Textbox it would be blocked and not appear in the Textbox. How to do it the…
-
31
votes5
answers3608
viewsCan the browser "remember" a password programmatically?
I am developing an application where from a password provided by the user a pair of keys (authentication and encryption) is derived. The password itself is never sent to the server, only the…
-
31
votes6
answers7191
viewsHow to put default (default) arguments in a Javascript function?
In R this would be very simple: funcao <- function(x=10) return(x) If you call funcao() without arguments the result will be 10. How to do the same in Javascript? And how to know if there are…
-
31
votes2
answers7772
viewsWhat characterizes imperative and functional programming?
What characterizes the imperative and functional programming and what are the differences between them in relation to each other? I cannot understand these two paradigms. Note: If you can cite…
javascript terminology functional-programming imperative-programmingasked 8 years, 9 months ago gato 22,329 -
31
votes3
answers1005
viewsHow to convert animation in Canvas/JS to SVG?
I’ve been using a javascript library to make icones/symbols of a weather app. I now wanted to do in SVG the symbol of the cloud (cloudy sky), and wonder what the best approach. I made a svg with the…
-
31
votes2
answers843
viewsIs it really necessary to put "text/javascript" in the <script> tag?
We are in 2016. I have read in some places on the internet that it is no longer necessary to use this statement type="text/javascript". In fact, use the tag script without declaring this excerpt…
-
31
votes1
answer1866
viewsWhat is the Webassembly?
Reading random articles, I read one that predicted the end of Javascript through Webassembly, which seems to be a way to get other languages to do Javascript’s work, but I’m sure this is a wrong…
-
31
votes6
answers7015
viewsHow to get unique values in a Javascript array?
In PHP, when I have one array with duplicated values, it is possible to obtain only unique values through the function array_unique. Example: $array = ['a', 'b', 'b', 'c', 'c'];…
-
30
votes7
answers46159
viewsRemove repeated elements within a Javascript array
How to remove repeated elements within a Javascript array? I have for example: var array = ['foo', 'bar', 'foo']; And I want to remove all duplicates to get: ['foo', 'bar']…
javascriptasked 10 years, 9 months ago user8789 301 -
30
votes2
answers22530
viewsHow to capture a photo through the user’s webcam and send via POST?
How to perform the user’s webcam image capture procedure on a registration form to submit via POST? I am looking for a solution that is compatible with most browsers and that is simple to implement.…
-
29
votes3
answers4056
viewsHow to get the value of the current percentage of an upload?
I’m working with PHP, but I imagine it can be done only with javascript/jQuery. When I upload the browser shows the percentage in the status bar. I would like to take this value and create from it a…
-
29
votes6
answers66760
views"foreach" in Javascript
By way of example, in PHP we have the function foreach() (English) which allows us to execute a certain code for each element found in a matrix: <?php $arr = array(1, 2, 3, 4, 5, 6); foreach…
-
29
votes8
answers95476
viewsHow to check with jQuery if there is a checkbox checked?
I would like to know which Checkbox is checked with Jquery. To catch all the checks I made the following code var checado=false; $(obj).find("input[name='analisar']").each(function(){…
-
29
votes3
answers10218
viewsHow to create a real-time notification system similar to Stack Overflow?
I am developing a Help Desk system, and would like some ideas on how to create a notification system similar to Stack Overflow itself, whenever some new support is registered. I intend to use PHP,…
-
29
votes3
answers660
viewsShould we validate function parameters?
In languages like Java, method parameters are "validated" in the build (at least the type): public void facaAlgo(String str) { // ... } // em algum outro lugar: int i = 2; this.facaAlgo(i); // erro…
-
29
votes7
answers53067
viewsKnowing if the number is odd or even
I wonder why nothing happens to my code. Even the variable n the alert appears, but then nothing else happens. var n = prompt("Digite um numero"); var total=n/2; if(n/2=0){ alert("Par"); }…
javascriptasked 9 years, 9 months ago larissa castro alves 293 -
29
votes1
answer1130
viewsWhen using async and Defer, is the order of the scripts respected?
For a single script, the load/run order in presence or not of attributes async and defer is clear: with nothing, loads and executes immediately, with async loads in parallel and performs at the end…
-
28
votes2
answers3688
viewsWhat are the advantages and disadvantages of minifying Javascript scripts?
And which mini-guards can I use?
-
28
votes3
answers466
viewsComments weigh in?
Comments weigh? I leave comments throughout my code, will influence something on the site? I’m saying more specifically in HTML, CSS, Javascript, PHP.
-
27
votes3
answers35092
viewsAjax cross-Omain request with pure Javascript (no Apis)
I have two applications in different domains, and I need to make a request Ajax between them saw POST or GET so cross-Domain. What would be the safest way to implement this in Javascript, without…