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
-
21
votes2
answers14288
viewsHow to disable a text field for editing using jQuery/Javascript?
Let’s say I have a form with fields 1 to 7. Something like: field-1 field-2 field-3 field-4 field-5 field-6 field-7 All these fields are in one form. With Laravel, sometimes I experienced situations…
-
21
votes4
answers44155
viewsHow to test null values in Javascript
I found the next code, and I got the impression that it didn’t make much sense. function (data) { if (data != null && data !== undefined) { // codigo } } From here, three different scenarios…
-
21
votes5
answers2054
viewsWhy put Javascript, CSS, and images on another server?
On most sites I noticed that they use another server to load scripts, CSS and images. Because they use?
-
21
votes4
answers7389
viewsHow to make Ajax requests, with Jquery, on different domains?
It is possible to request a POST type to a url that is not part of the domain of our application? $.ajax({ type: "POST", url: "http://www.dominioexterno.com.br/acao/", data: { var1:…
-
21
votes2
answers8317
viewsHow to delete a variable in Javascript?
I program in other languages, I’m still starting in Javascript. I was testing the mgibsonbr response code to this question and found a difficulty that may be trivial. If I define var x = 0 in the…
-
21
votes5
answers27254
viewsClear browser caching with Javascript
Is it possible to clear the cache of Firefox and Chrome browsers via Javascript? With Internet Explorer I can, but not mentioned above. Dude, it didn’t work, I think the problem occurs because save…
-
21
votes2
answers1671
viewsIs it possible to add an overflow behavior with scroll only in tbody of a table?
It is possible to add a behavior of overflow with scroll only in the tbody of a table and still not have to set fixed sizes in pixels, without having to separate the column header with the body, as…
-
21
votes6
answers65532
viewsSum in 2 inputs and appear in real time - Javascript
My question is the following: I have two inputs type text. One person put a number in input 1 and another number in input 2. When the person had just filled in, the result of adding the 2 inputs…
-
21
votes2
answers548
viewsWhat’s the difference between a js file with . min and no . min?
What is the file difference Javascript containing .min (for example jQuery.min.js) and the file without the .min (for example jQuery.js)?…
-
21
votes3
answers2168
viewsHow to Make Icone Ride in the Google Maps api
In this My script below it every 30 seconds causes the icone to change position, only the icone disappears and appears at the next point. What I wanted was for him to walk up to the next point as…
-
20
votes3
answers12960
viewsWhat is the difference between double quotes and single quotes in Javascript?
Context In PHP, there is a difference between using single and double quotes. In this case, single quotes are for "strings common", and double quotation marks, used when processing string…
javascriptasked 11 years ago Calebe Oliveira 4,527 -
20
votes2
answers523
viewsWhy should we use Anonymous functions with jQuery instead of the function directly?
I have a question, some methods of jQuery expect a function as parameter, but to work they must receive an Inner Function as parameter instead of a function directly, as in the example below:…
-
20
votes7
answers43303
viewsHow do I know if a variable is of the Javascript Number type?
In javascript, because there is no declaration of the types of variables such as Integer, String, Boolean, etc., it is a difficult task to know what kind of value you are dealing with in a given…
-
20
votes4
answers552
viewsHow to distribute words in a fixed size area?
I have a list of words and I need to distribute them in an area of fixed dimensions so that it looks like they were randomly arranged in that space. However, I need to make sure that the words do…
-
20
votes4
answers6604
viewsHow to extract a file extension in Javascript?
There are some cases where I need to capture a file extension (that is, a string with the file address) in order to validate the extension via Javascript. For example of location: var path =…
-
20
votes1
answer3182
viewsWhat is and how does context (this) work in Javascript?
Essential part of Javascript, every function has context (this). How it works, how to manipulate it and what changes in strictly speaking ('use strict')?…
-
20
votes4
answers6633
viewsWhat is the difference between pre and post increment in Javascript?
The most common and known form of increment is the post: for (var i = 0; i < 10; i++){ console.log(i); } However, I then see the pre-decrease: for (var i = 0; i < 10; ++i){ console.log(i); }…
javascriptasked 10 years, 9 months ago Andre Figueiredo 5,030 -
20
votes3
answers32049
viewsHow to check if a variable is set?
I tried to do it that way: else if (vCodUG === undefined) and made an error of: Uncaught Referenceerror: vCodUG is not defined…
-
20
votes1
answer9558
viewsIs there official documentation for Javascript?
Is there any official Javascript documentation like you have PHP.net or jQuery.com? When we search on Google nothing like Javascript appears.com...
-
20
votes3
answers8663
viewsWhat is the difference between DOM and virtual DOM?
I saw a framework that worked with Virtual DOM and thus became faster than the others. (framework : facebook reactjs) What is the advantage and disadvantage in each one? How to work with each one?…
javascriptasked 10 years, 2 months ago Rod 9,412 -
20
votes4
answers6072
viewsHow to write code as an example, without running?
I’m doing the translation of a book to an HTML page, ai in the book has the codes, but how do I make my HTML display my code, HTML, PHP and Javascript, without running them?
-
20
votes4
answers55577
viewsHow to validate client-side CPF with script?
I’m working with a CPF validation on my controller, but I need to validate when the customer leaves the input of the CPF and then return a message warning when the CPF is incorrect, through a alert…
-
20
votes1
answer261
viewsWhat is the difference between these two implementations?
I was reading some articles about Patterns and I had a doubt in the following two examples. Suppose I have a single function that returns an element to me through the ID sent as argument. The first:…
javascriptasked 9 years, 10 months ago Renan Gomes 19,011 -
20
votes6
answers14943
viewsJS Mask for Hours Validation
I’m using in a project the jQuery Masked Input. I made a mask like this: <script> $(document).ready(function () { $("#QuantidadeHoras").mask("99:99"); }); </script> The <input>…
javascript jquery jquery-masked-input jquery-mask-pluginasked 9 years, 7 months ago Leonel Sanches da Silva 88,623 -
20
votes3
answers2999
viewsWhat is the difference between for...of and for.. in?
I was taking a look at that question from the SOEN and there I saw this for..of. I’ve never seen that before in Javascript. This is a new resource and we can implement it reliably, or we should…
-
20
votes3
answers3474
viewsWhy is it sometimes necessary to setTimeout with a value of 0 (zero)?
I have observed for some time that some types of event only work correctly when we define a certain function that is called with the setTimeout worthwhile 0. On the contrary, if we call this…
-
20
votes2
answers5648
viewsWhat is Ecmascript 2015 (ES6) specification?
I recently started a project with Cordova + Ionic and, at a certain point, I entered an impasse in which I found the affirmative that the framework follows the "latest" web standards such as the new…
-
20
votes3
answers20650
viewsWhen to use Success: Function() and . done(Function()) in asynchronous requests?
Simply put, I can write an asynchronous request like: $.ajax({ url: url, dataType: 'json', type: 'GET', success: function (_user){ alert (_user) } }); that alerts me to the return _user. Likewise, I…
-
20
votes3
answers2779
viewsWhat are React Hooks?
I would like to understand the concept and if possible with examples of this new Feature react. What will change in the way you create projects with React? The community seems to have enjoyed, what…
-
19
votes1
answer409
viewsWhy doesn’t Google Chrome allow you to copy a reference to the console.log function?
I have a method that receives a reference to a function and uses that reference to display a data (code below). The problem is that when I use the function console.log by Google Chrome, there is an…
-
19
votes2
answers1202
viewsWhat is the name of this 'effect' of selecting objects and how to do it in pure JS?
I wanted to know what is the name of this 'effect' ('-') that serves to select folders and files in Windows Explorer. And if possible wanted to know how to do this with pure Javascript.…
javascriptasked 11 years ago Iago Bruno 1,693 -
19
votes3
answers1755
viewsHow does the Flux architecture work?
Reactjs brought with it a new architecture, also used for Facebook and Yahoo! I wonder how it works, what exactly is a Dispatcher, Store, Action... If possible, on the basis of the MVC.…
-
19
votes3
answers1826
viewsHow to calculate PI with "n" decimal places in Javascript?
Using the object Math of Javascript, I can return an PI value with fixed decimal places, example: Math.PI //3.141592653589793 But in case I need (yes, very unusual) calculate the same with more…
-
19
votes1
answer15921
viewsWhen to use module.Exports or Exports on Node.js?
I am starting my study with Node and I came across the two ways to export something so that it is available with the require, I would like to know what is the best way and why. Thank you…
-
19
votes1
answer403
viewsHow does Symbol work on ES6?
In the new Javascript specification Ecmascript (ES6) a new primitive type was created called Symbol() what use it is?…
-
19
votes4
answers1173
viewsWhat does the regular expression "/(?=(?:...)*$)/" do in detail?
I just needed a solution to put points to separate numbers from three to three, backwards. For example: 1000 => 1.000 100000 => 100.000 10000000 => 1.000.000 In a reply I found in English…
-
19
votes3
answers910
viewsHow to use $.on in pure Javascript: "$(...). on(event, selector, function)"?
It is as follows, in jQuery we have the on, any element <a> with class test and without the class foo will trigger the function when clicked, even if you create the element later the event is…
-
19
votes3
answers1712
viewsWhy is it considered wrong/bad to repeat an HTML ID?
I think the title says it all, why is it considered wrong to repeat HTML Ids? I notice a lot of people doing things like: <div id="foo">bar</div> <div id="foo">baz</div> To…
-
19
votes2
answers2430
viewsUsing && e || instead of "if" and "Else"
Lately I’ve seen some codes that use && and || to replace if and else , and even to do checks with less code. I’m using this technique quite smoothly so far. Follow an example code: const…
-
18
votes7
answers44529
viewsHow to get only the numbers of a string in Javascript?
I wonder if there are functions that return only the numeric values of a string, if there is not, what is the simplest and efficient way to implement? Example: apenasNumeros("5tr1ng"); Upshot: 51…
-
18
votes4
answers7395
viewsWhat’s different from jQuery’s find and filter?
I remembered that there is a function in jQuery called filter. I already know the find, but I want to know if there’s any difference between them or if they’re the same thing.…
-
18
votes3
answers39348
viewsFunction to add more hours or days to a date
I don’t know much about function new Date() and wanted a way to add days/hours on a date. Example: I have: var Time = "14/03/2014 23:54"; and I want to add 2 hours to Team, then he adds the 2 hours…
javascriptasked 10 years, 11 months ago Iago Bruno 1,693 -
18
votes4
answers20028
viewsDetect if an element contains a class with pure Javascript
In jQuery, we have the code $("#elemento").hasClass("nomeDaClasse"); Which indicates if an element contains a certain CSS class. How can I achieve the same with pure Javascript?…
javascriptasked 10 years, 11 months ago Tiago César Oliveira 2,855 -
18
votes2
answers23417
viewsHow to select an option in one <select> and load related data in another?
I would like to select an option of a <select> and fill in the other <select> with related content. I will only be able to do this with the information stored in the database or has how…
-
18
votes3
answers11309
viewsHow to delete duplicate spaces in a string?
I have the following string: var str = "00000.00000 111111111.111111111111 33333333" I need to remove the extra spaces for it to look like this (only with 1 space): var str = "00000.00000…
-
18
votes3
answers1335
viewsWhy is it bad practice to use Javascript inline?
The title already describes the question: why is it considered a bad practice to use CSS and Javascript inline in our codes? It’s bad to use it even on smaller projects?
javascriptasked 10 years, 7 months ago waghcwb 1,915 -
18
votes2
answers1120
viewsWhat is the use and when to use version in . js and . css files?
What it’s for and when to use js? v=123(example) css file? v=123(example) What benefits and how the browser interprets this
-
18
votes2
answers2027
viewsWhat are operators for | & << >>?
I was analyzing a code and found some operators I don’t know: |, &, >> and <<. What is the functionality of these operators? bits = h1 << 18 | h2 << 12 | h3 << 6 |…
-
18
votes1
answer897
viewsStreaming type 'livestreaming' with javascript
I’m developing a project of Livestreaming(Live video streaming) and would like to know if it is possible to make this broadcast using websockets, javascript and html5 video capture where would have…
-
18
votes2
answers4788
viewsIs it possible to use masks on mobile devices satisfactorily?
So after a true pilgrimage that yielded about 10 questions, I discovered that the masks I was wearing didn’t work properly on mobile devices. The main ones are (were?): Maskmoney inputMask What…