Linked Questions

3140 votes
47 answers
3.1m views

Is there a standard function to check for null, undefined, or blank variables in JavaScript? [duplicate]

Is there a universal JavaScript function that checks that a variable has a value and ensures that it's not undefined or null? I've got this code, but I'm not sure if it covers all cases: function ...
Alex's user avatar
  • 36k
130 votes
5 answers
609k views

Javascript: How to check if a string is empty? [duplicate]

I know this is really basic, but I am new to javascript and can't find an answer anywhere. How can I check if a string is empty?
Andrew's user avatar
  • 241k
18 votes
1 answer
13k views

JS how to check empty String and Space [duplicate]

Help me pls if(value == ""){ // do anything } but I need to check space " " (2,3,... space is include) is the same way of empty String ps. sorry in my English
JinkleBell Surcharoen's user avatar
-4 votes
3 answers
56k views

How can I check if the input is empty in JavaScript? [duplicate]

I am trying to make a factorial calculator. How can I check if the input is empty or not? I tried 'null'. But it didn't work or I couldn't use it properly. sorry for the stupid question. I am newbie ...
Sajib Devnath Akash's user avatar
9 votes
0 answers
20k views

Validating a non-empty String in Lo-Dash [duplicate]

[Use-case: portable Lo-Dash code] I've been looking for an elegant Lo-Dash empty-string validator in our nodeJS projects for some time now, because _.isEmpty() only handles Arrays and Objects. So I ...
sneeuwitje's user avatar
3 votes
2 answers
11k views

How to check empty in variable in Google Apps Script [duplicate]

I have a variable that can be either empty, number or text. I like to find only empty one. But the following codes using .length returned null for 0 number, though it returned 1 for "0" ...
Newbie's user avatar
  • 283
5 votes
1 answer
618 views

String check with if js shorthand [duplicate]

I have var names = []; and want push there some string only if it's not empty. Is there way make it with some shorthand method in js?) That i have now. if ("" != opportunityName) { names....
Maks Martynov's user avatar
-1 votes
1 answer
508 views

If input has spaces only [duplicate]

Hi there everyone how can I detect if the user input has just empty spaces? Detect this: input = ' '; input = ' '; etc... DO NOT detect this: input 'hi there'; I just want to detect if ...
pixie123's user avatar
  • 989
0 votes
1 answer
258 views

Checking the input if its empty [duplicate]

I am pretty new to jQuery so I have a problem with this. I am trying to check if input is empty by jQuery. I have this script: $('#submit').click(function(){ if($.trim($('#username').val()) == ...
Adam Šulc's user avatar
-1 votes
1 answer
104 views

How to check if value contains at least one character, expect for space [duplicate]

I`m building messaging app and I need regex or some other way to validate message that user is about to send. Message must contain at least one character, expect for space. const valid = *regex* ...
George Alexander's user avatar
-5 votes
1 answer
90 views

How to shorten text in Javascript [duplicate]

I am trying to reduce the length of the text that I have requested from the API with the 'slice' method. but it is throwing an error of 'Cannot read property 'slice' of undefined.
Louigee's user avatar
1 vote
0 answers
88 views

How do I get the console to print out the name, keeping in mind the name variable isn't constant? [duplicate]

I'm trying to create a ternary expression that decides what to do if the user enters a name or not. If the user enters a name — like 'Jane' — use string interpolation to log Hello, Jane! to the ...
helloworldio's user avatar
0 votes
0 answers
18 views

Boolean conditionals with placeholder [duplicate]

super beginner here: I having trouble figuring out how to correctly use this conditional statement for a placeholder. For some reason, it only executes one condition after clicking on submit (in this ...
taram414's user avatar
5644 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
3889 votes
41 answers
4.4m views

How do I test for an empty JavaScript object?

After an AJAX request, sometimes my application may return an empty object, like: var a = {}; How can I check whether that's the case?
falmp's user avatar
  • 39.3k

15 30 50 per page
1
2 3 4 5 6