Questions tagged [null]

Null means *nothing* or *unknown*, depending on context. Please use the "sql-null" tag for SQL specific questions.

"Null" has different meanings depending on context.

Set theory

Null is another name for the empty set, denoted by the symbol ∅. For this reason, some programming languages use null or nil for the empty list or empty tuple. Lisp uses nil to mean the empty list and the boolean value false.

Pointers and References

Null (or sometimes nil or None), in programming languages that support it, is the value of an uninitialized variable, a pointer that doesn't point to a meaningful memory address, or an object that fails to respond to any message.

Nullable references were invented by C.A.R. Hoare in 1965 as part of the Algol W language. Hoare later described his invention as a "billion-dollar mistake".

For more information, see Null pointer.

Agreeing with Hoare's sentiment, many languages don't have a special null value, choosing to use optional types instead.

Relational Databases

NULL as a special marker in SQL or a relational database stands in place of a value that is missing, or in a join means "no corresponding row." The operators IS NULL and IS NOT NULL are required for comparisons to a literal null: other comparisons between NULL and any value evaluate to "unknown."

For more information, see Null (SQL).

ASCII

Null or NUL is the name given to the character with ASCII code zero (0) - i.e. hex 00. In some languages, notably C, NUL is used to mark the end of a character string.

For more information, see Null character.

16208 questions
4377
votes
66 answers

How do I avoid checking for nulls in Java?

I use x != null to avoid NullPointerException. Is there an alternative? if (x != null) { // ... }
Goran Martinic
  • 3,807
  • 4
  • 21
  • 14
3929
votes
54 answers

How do I check for an empty/undefined/null string in JavaScript?

Is there a string.Empty in JavaScript, or is it just a case of checking for ""?
casademora
  • 67,775
  • 17
  • 69
  • 78
3026
votes
47 answers

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

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 isEmpty(val){ return (val === undefined || val ==…
Alex
  • 34,699
  • 13
  • 75
  • 158
2645
votes
34 answers

How can I determine if a variable is 'undefined' or 'null'?

How do I determine if a variable is undefined or null? My code is as follows: var EmpName = $("div#esd-names div#name").attr('class'); if(EmpName == 'undefined'){ // DO SOMETHING };
But when I…
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
1870
votes
26 answers

What is a NullReferenceException, and how do I fix it?

I have some code and when it executes, it throws a NullReferenceException, saying: Object reference not set to an instance of an object. What does this mean, and what can I do to fix this error?
John Saunders
  • 160,644
  • 26
  • 247
  • 397
1624
votes
39 answers

What is the difference between null and undefined in JavaScript?

I want to know what the difference is between null and undefined in JavaScript.
user605334
1590
votes
8 answers

Is null check needed before calling instanceof?

Will null instanceof SomeClass return false or throw a NullPointerException?
Johan Lübcke
  • 19,666
  • 8
  • 38
  • 35
1458
votes
9 answers

Null object in Python

How do I refer to the null object in Python?
Lizard
  • 43,732
  • 39
  • 106
  • 167
1360
votes
14 answers

Altering a column: null to not null

I have a table that has several nullable integer columns. This is undesirable for several reasons, so I am looking to update all nulls to 0 and then set these columns to NOT NULL. Aside from changing nulls to 0, data must be preserved. I am looking…
Karmic Coder
  • 17,569
  • 6
  • 32
  • 42
1307
votes
25 answers

Which @NotNull Java annotation should I use?

I'm looking to make my code more readable as well as use tooling like IDE code inspection and/or static code analysis (FindBugs and Sonar) to avoid NullPointerExceptions. Many of the tools seem incompatible with each others'…
jaxzin
  • 13,471
  • 4
  • 19
  • 19
931
votes
25 answers

Why is null an object and what's the difference between null and undefined?

Why is null considered an object in JavaScript? Is checking if ( object == null ) Do something the same as if ( !object ) Do something ? And also: What is the difference between null and undefined?
rahul
  • 184,426
  • 49
  • 232
  • 263
845
votes
24 answers

How do I check for null values in JavaScript?

How can I check for null values in JavaScript? I wrote the code below but it didn't work. if (pass == null || cpass == null || email == null || cemail == null || user == null) { alert("fill all columns"); return false; } And…
Mahdi_Nine
  • 14,205
  • 26
  • 82
  • 117
761
votes
21 answers

Why is my Spring @Autowired field null?

Note: This is intended to be a canonical answer for a common problem. I have a Spring @Service class (MileageFeeCalculator) that has an @Autowired field (rateService), but the field is null when I try to use it. The logs show that both the…
chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
646
votes
29 answers

How to check for an undefined or null variable in JavaScript?

We are frequently using the following code pattern in our JavaScript code if (typeof(some_variable) != 'undefined' && some_variable != null) { // Do something with some_variable } Is there a less verbose way of checking that has the same…
Tomas Vana
  • 18,317
  • 9
  • 53
  • 64
622
votes
8 answers

Representing null in JSON

What is the preferred method for returning null values in JSON? Is there a different preference for primitives? For example, if my object on the server has an Integer called "myCount" with no value, the most correct JSON for that value would…
pherris
  • 17,195
  • 8
  • 42
  • 58
1
2 3
99 100