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
-
177
votes4
answers72185
viewsWhat is a callback?
I see in many codes and even architectures the word callback, I see that it is in Javascript functions. But what is? How is it used? Why? I’d like an example of real use.…
-
174
votes6
answers5796
viewsHow is computer randomization generated?
Doubts How computer randomization is done? What algorithm or mathematical basis does the computer use to generate those numbers? For example: No Javascript utilizo o Math.random() it returns me…
-
148
votes5
answers6116
viewsWhat is the difference between the functions var name = Function() and Function name()?
I see in some codes different ways to define a function, but I don’t know the difference if it exists. What is the difference between these functions? Function 1 function teste(valor){ return (valor…
javascriptasked 10 years, 5 months ago Paulo 9,980 -
143
votes10
answers34548
viewsWhat is the difference between the == and === Javascript operators?
I have the following Javascript code: var x = 0; if (x === false) { // não acessa } if (x == false) { // acessa } Why the expression with the operator == returns true and with the operator ===…
-
124
votes5
answers9611
viewsHow do Closures work in Javascript?
I always wanted to know how Closures work in Javascript, I’ve read some settings but never understood very well. Could you give me a simple, objective but content explanation?
-
123
votes9
answers13997
viewsHow to create a website without reloading every click on a link?
I’m looking to develop a site that runs all in the same file, but I’m not sure how to look for study material for this. Thus: Normal site->I’m on the Index.php page. When I click on the…
-
117
votes7
answers78990
viewsHow does this if/Else work with "?" and ":"?
I am studying Javascript and I have doubts about the different ways to make a if/ else. For example, this: foo ? foo : foo How exactly does it work?…
-
111
votes7
answers13788
viewsHow to represent money in Javascript?
What is the best way to represent monetary units (i.e. money) in Javascript? I know it is not good to use floating point, given the rounding problem, but I do not know what would be the best…
-
108
votes4
answers48488
viewsWhere should I put a Javascript code in an HTML document?
Where Javascript code should be placed in an HTML document: in the element <head> or <body>? At the beginning or end of each one? Is there any difference in performance or any other…
-
89
votes6
answers9431
viewsWhen should var be used in Javascript?
I’m always in doubt in the projects I put var before giving a value to a variable or not because both work (I think). Can anyone explain why they use it or not? What convention or good practice to…
javascriptasked 10 years, 8 months ago Joao Paulo 11,760 -
85
votes6
answers32107
viewsWhat is Vanilla JS?
I have already found in several places this term, "Vanilla JS". It seems to be cited as a framework, but in the codes where it is cited and in the site itself the code presented is pure Javascript.…
-
82
votes5
answers86551
viewsUpload a file with AJAX
I wonder if there is any simple way to upload files via AJAX + JSON. If there is, what would it be?
-
79
votes8
answers16873
viewsHow to invert a string in Javascript?
How to invert a string in Javascript? For example: Entree: "something here" Exit: "iuqa asioc amugla"
-
78
votes12
answers208289
viewsHow to format date in Javascript?
I want to play the current date on one input, but in the "Brazilian" dd/mm/yyyy. My code: var data = new Date(); dataFormatada = ????? $("#Data").val(dataFormatada);…
-
78
votes6
answers24661
viewsWhat is the difference between declaring variables using Let and var?
Since the word was introduced let in the Ecmascript I have only heard about it, so far I have not seen any practical example and to be honest I do not know very well what is a variable let and how…
-
69
votes3
answers4929
viewsWhat is the point of using double negation in Javascript?
Recently, while studying some Javascript codes, I came across the following code: return !!navigator.userAgent.match(/iPad/i); I know that: !true == false !false == true And consequently: !!true ==…
javascriptasked 10 years, 1 month ago Lucas Lima 6,714 -
67
votes3
answers5939
viewsWhat are the techniques for making scroll-based animations?
I’m interested in creating websites with scroll-driven animation (ex.: Kano), where content is animated and replaced as the page is scrolled. What are the techniques to facilitate such programming?…
-
67
votes1
answer722
viewsWhy (!+[]+[]+![]). length returns 9 in Javascript?
I just read that article and in it there is this expression: (!+[]+[]+![]).length Evaluating this in the interpreter: > (!+[]+[]+![]).length 9 Good, why?…
javascriptasked 10 years, 1 month ago Lucas Virgili 3,092 -
66
votes6
answers27772
viewsWhen, why and how to use the "use Strict" directive in Javascript?
I had never seen before the use of this directive, but almost all the most mature jQuery plugins use it. I would like to know when and how to use it and what its purpose is.
-
66
votes5
answers24456
viewsAJAX request with pure Javascript (no Apis)
Usually, when we need to resort to requisitions AJAX using Javascript, we have handy Apis that help us with this (e.g.: jQuery). However, what would be the safest and cross-browser to make these…
-
66
votes7
answers12436
viewsUse semicolon or not at the end of the lines in Javascript?
I have read some comments on the web about whether or not to use the ; at the end of the lines when writing Javascript. Some say yes, others say no need, but none can explain well the reasons for…
-
63
votes2
answers5844
viewsCoffeescript, Typescript and Javascript
Among Javascript studies, I found in some places many people suggesting the use of Coffeescript or Typescript to accelerate the development process. If I understand correctly, both are like a…
-
63
votes3
answers1056
viewsWhat is "with" for in Javascript?
What is the purpose of the with in Javascript? It works only to get the object values as if it were a variable, or it is also possible to set or change properties through it? Example: var obj =…
-
61
votes1
answer1802
viewsHow do prototypes work in Javascript?
It seems to me that the concept of prototype is fundamental in Javascript and even in several places I have read that is one of its strengths. However, this does not seem such a simple concept to…
-
61
votes4
answers49363
viewsWhat is console.log?
I see this in some Javascript files: console.log(algumaCoisa); console.log("alguma coisa"); What it’s for and how it works? I’m trying to make a log() customized for a Userscript (see How can I log…
javascriptasked 9 years, 11 months ago brasofilo 6,560 -
57
votes4
answers16863
viewsCross-browser way of copying text to the Clipboard (Clipboard)
I’m looking for ways to copy a text to the clipboard (Clipboard) via Javascript, which works on most modern browsers, but there is too much information and seems to me outdated. I know there is a…
-
57
votes2
answers3691
viewsWhat is DOM, Render Tree and Node?
I’m a beginner in JS and try to understand the theory, but all the articles I find on DOM are too "scientific". There wouldn’t be a simpler way to explain this to a "layman"?
-
57
votes3
answers1826
viewsWhy use getElementById if id is in the window?
Recently in my study I noticed an object that manipulated the DOM of the element that had the same name in its id. teste.style.border = '1px solid #CCC'; teste.style.width = '500px';…
-
54
votes2
answers126902
viewsWhat is the difference between $(Document). ready() and window.onload?
There is a difference between $(document).ready() e window.onload apart from one being Javascript and the other being jQuery? I see both events are triggered as soon as the GIFT (Document Object…
-
51
votes1
answer24387
viewsWhat is the difference in the use of Return false, Event.stopPropagation() and Event.preventDefault()?
Num Handler jQuery event, one can use return false, event.stopPropagation() and event.preventDefault() (or combinations thereof) to "cancel the action" of the event. I know there’s a difference in…
-
51
votes6
answers15594
viewsHow to do a search ignoring Javascript accent?
Suppose I have a list of words, in Javascript (if necessary, already ordered according to the rules of collation): var palavras = [ "acentuacao", "divagacão", "programaçao", "taxação" ]; Notice I…
-
51
votes8
answers2113
viewsIs using customer validation enough?
Using Javascript validations is sufficient for efficient validation? Example: Date validation. It is necessary to check also in the code? What are the disadvantages of only performing validations…
-
51
votes3
answers3927
viewsWhat is the difference between $(this) and $this and this?
I’ve always used the $(this) independent of the situation and always worked. Rarely have I had to use one of the others and on those occasions I did it for someone’s guidance and not for knowing…
-
48
votes6
answers18641
viewsWhat is the difference between declaring an array with "array()" and "[]" in Javascript?
In Javascript we can declare an array in two ways: var matriz = new Array(); and var matriz = []; What is the difference between the two and what the consequences are? This question is being asked…
-
47
votes3
answers12057
viewsDifferences between localStorage Vs sessionStorage?
What are the differences, pros and cons between localStorage and sessionStorage?
-
46
votes2
answers2271
viewsHow do you really learn how to use Javascript promises?
For a while I’ve been trying to learn how to use promises and asynchronous programming in Javascript, but so far I haven’t had much success in it. I already understood that there are functions that…
javascriptasked 10 years, 4 months ago SomeDeveloper 18,074 -
45
votes5
answers76380
viewsHow to pin a "horizontal menu" to the top of the window when scrolling the page?
I have a layout with a horizontal navigation bar at the top of the site, it is with margin-top:100px, when scrolling the page the menu should be fixed at the top of the window but with margin-top:0.…
-
45
votes3
answers3408
viewsHow to find out if a hexadecimal color is dark or light?
I have a status listing that is displayed and each status has an assigned color. These colors are saved in my database in hexadecimal format. Example: #add555 I have a small problem: If the color is…
-
44
votes5
answers87966
viewsHow to print content inside a HTML div?
I have a page and in it the content I want to print. I created a Javascript command, but this command prints the whole page. Is there any way to print only the contents of a div?…
-
43
votes4
answers1480
viewsWhat is the correct way to simulate a <script> with a new language?
Suppose I implemented a new language and I have a functional interpreter written in javascript. Something like mylang.interpret(code_as_string). Now I would like to create an interface in which I…
-
43
votes2
answers6588
viewsHow can I pause and play a gif?
I want to put on my site, a system like 9gag, where people can pause and give play in a .gif. I know I have to use two images, one .jpg and a .gif, but tried some functions and could not. I found…
-
43
votes5
answers22471
viewsHow do anonymous functions work?
I know they are functions that do not have the specified name, but what is the purpose? Is it possible to recur with anonymous functions? Ex: Fibonacci sequence. (function(x, y) { alert(x + y);…
-
43
votes3
answers9745
viewsWhat are Javascript Promises (promises)?
I was researching about callback in Javascript when I found this question: How to really learn to use Promises (promises) in javascript? But after all : What are promises? What are they for?…
-
42
votes3
answers3888
viewsWhy is using global variables not good practice?
I’m reading a Javascript book called "Javascript The Good Parts" and in it at various times the author says that one should not use global variables because they are of "evil". Why are they…
-
42
votes4
answers18382
viewsWhat is the difference between null and Undefined?
Most programming languages have a "null" type to represent the absence of a value. It can have multiple names (null, nil, None, etc), but its purpose is the same (with the exception of SQL, where…
-
42
votes14
answers126839
viewsPhone Mask Using jQuery Mask Plugin
I need to change the "-" position on the mask. <label for="telefone" >Telefone</label> <input style="width:25%; margin-right:25% " type="tel" name="telefone" id="telefone"…
-
42
votes2
answers1922
viewsWhy do they say that recursive setTimeout is better than setInterval?
I see online a series of articles with titles like: setInterval is bad, which translating would be setInterval is ruin. I saw recommendations to use an anonymous recursive function with a…
-
42
votes6
answers3282
viewsIs there a Javascript class?
I am studying Javascript and saw some explanations that left me with doubts. Here at Stackoverflow I saw several questions about the possibility of creating an abstract class in Javascript. But my…
-
41
votes2
answers15929
viewsHow to transform numeric digits into numbers in full?
I’d like to know how to turn numerical digits in spelled numbers, as shown in the example below: 0 -> retorna "zero" 5 -> retorna "cinco" 2014 -> retorna "dois mil e quatorze" 1034 ->…
javascriptasked 10 years, 7 months ago Cabeção 1,799 -
40
votes3
answers39993
viewsHow to implement google reCAPTCHA on my website?
I’m trying to implement the reCAPTCHA from Google on my site, and I can’t do the integration Server-Side (I use the language PHP). How can I make reCAPTCHA work, and perform the validation before…