Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [javascript]

For questions about programming in ECMAScript (JavaScript/JS) and its different dialects/implementations (except for ActionScript). Note that JavaScript is NOT Java. Include all tags that are relevant to your question: e.g., [node.js], [jQuery], [JSON], [ReactJS], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

11987 votes
150 answers
12.8m views

How can I remove a specific item from an array in JavaScript?

How do I remove a specific value from an array? Something like: array.remove(value); Constraints: I have to use core JavaScript. Frameworks are not allowed.
Walker's user avatar
  • 133k
8699 votes
67 answers
3.2m views

How do I check if an element is hidden in jQuery?

How do I toggle the visibility of an element using .hide(), .show(), or .toggle()? How do I test if an element is visible or hidden?
Philip Morton's user avatar
8494 votes
32 answers
1.2m views

What does "use strict" do in JavaScript, and what is the reasoning behind it?

Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error: Problem at line 1 character 1: Missing "use strict" statement. Doing some searching, ...
Mark Rogers's user avatar
  • 97.4k
7698 votes
58 answers
7.9m views

How do I redirect to another webpage?

How can I redirect the user from one page to another using jQuery or pure JavaScript?
venkatachalam's user avatar
7639 votes
42 answers
1.2m views

var functionName = function() {} vs function functionName() {}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent. The previous developer used two ways ...
Richard Garside's user avatar
7615 votes
86 answers
1.6m views

How do JavaScript closures work?

How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves? I ...
7521 votes
39 answers
3.3m views

How do I remove a property from a JavaScript object?

Given an object: let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; How do I remove the property ...
johnstok's user avatar
  • 97.8k
7406 votes
3 answers
8.1m views

How to check whether a string contains a substring in JavaScript?

Usually I would expect a String.contains() method, but there doesn't seem to be one. What is a reasonable way to check for this?
6709 votes
42 answers
2.1m views

How do I return the response from an asynchronous call?

How do I return the response/result from a function foo that makes an asynchronous request? I am trying to return the value from the callback, as well as assigning the result to a local variable ...
Felix Kling's user avatar
6332 votes
72 answers
4.4m views

How do I include a JavaScript file in another JavaScript file?

How do I include a JavaScript file inside another JavaScript file, similar to @import in CSS?
Alec Smart's user avatar
  • 95.3k
6293 votes
38 answers
2.3m views

What is the difference between "let" and "var"?

ECMAScript 6 introduced the let statement. I've heard that it's described as a local variable, but I'm still not quite sure how it behaves differently than the var keyword. What are the differences? ...
TM.'s user avatar
  • 110k
5725 votes
41 answers
5.4m views

Loop (for each) over an array in JavaScript

How can I loop through all the entries in an array using JavaScript?
Dante1986's user avatar
  • 59.4k
5645 votes
47 answers
2.2m views

Which equals operator (== vs ===) should be used in JavaScript comparisons?

I'm using JSLint to go through JavaScript, and it's returning many suggestions to replace == (two equals signs) with === (three equals signs) when doing things like comparing idSele_UNVEHtype.value....
bcasp's user avatar
  • 57.4k
5478 votes
50 answers
4.6m views

How do I replace all occurrences of a string in JavaScript?

Given a string: string = "Test abc test test abc test test test abc test test abc"; This seems to only remove the first occurrence of abc in the string above: string = string.replace('abc', ...
Ali's user avatar
  • 266k
5471 votes
79 answers
4.8m views

How can I validate an email address in JavaScript?

I'd like to check if the user input is an email address in JavaScript, before sending it to a server or attempting to send an email to it, to prevent the most basic mistyping. How could I achieve this?...

15 30 50 per page
1
2 3 4 5
168928