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
614
votes
9 answers

JavaScript checking for null vs. undefined and difference between == and ===

How do I check a variable if it's null or undefined and what is the difference between the null and undefined? What is the difference between == and === (it's hard to search Google for "===" )?
MUG4N
  • 19,377
  • 11
  • 56
  • 83
608
votes
9 answers

How to filter empty or NULL names in a QuerySet?

I have first_name, last_name & alias (optional) which I need to search for. So, I need a query to give me all the names that have an alias set. Only if I could do: Name.objects.filter(alias!="") So, what is the equivalent to the above?
Val Neekman
  • 17,692
  • 14
  • 63
  • 66
593
votes
15 answers

How can I check if a string is null or empty in PowerShell?

Is there a built-in IsNullOrEmpty-like function in order to check if a string is null or empty, in PowerShell? I could not find it so far and if there is a built-in way, I do not want to write a function for this.
pencilCake
  • 51,323
  • 85
  • 226
  • 363
582
votes
5 answers

return, return None, and no return at all?

Consider these three functions: def my_func1(): print "Hello World" return None def my_func2(): print "Hello World" return def my_func3(): print "Hello World" They all appear to return None. Are there any differences between how the…
Clay Wardell
  • 14,846
  • 13
  • 44
  • 65
572
votes
26 answers

IllegalArgumentException or NullPointerException for a null parameter?

I have a simple setter method for a property and null is not appropriate for this particular property. I have always been torn in this situation: should I throw an IllegalArgumentException, or a NullPointerException? From the javadocs, both seem…
Mike Stone
  • 44,224
  • 30
  • 113
  • 140
562
votes
3 answers

What is the difference between "x is null" and "x == null"?

In C# 7, we can use if (x is null) return; instead of if (x == null) return; Are there any advantages to using the new way (former example) over the old way? Are the semantics any different? Is it just a matter of taste? If not, when should I use…
Maniero
  • 10,311
  • 6
  • 40
  • 85
550
votes
36 answers

Should a retrieval method return 'null' or throw an exception when it can't produce the return value?

I am using java language,I have a method that is supposed to return an object if it is found. If it is not found, should I: return null throw an exception other Which is the best practise or idiom?
Robert Deml
  • 12,390
  • 20
  • 65
  • 92
527
votes
6 answers

What is the difference between Nullable.HasValue or Nullable != null?

I always used Nullable<>.HasValue because I liked the semantics. However, recently I was working on someone else's existing codebase where they used Nullable<> != null exclusively instead. Is there a reason to use one over the other, or is it purely…
lc.
  • 113,939
  • 20
  • 158
  • 187
396
votes
9 answers

In C#, what happens when you call an extension method on a null object?

Does the method get called with a null value or does it give a null reference exception? MyObject myObject = null; myObject.MyExtensionMethod(); // <-- is this a null reference exception? If this is the case I will never need to check my 'this'…
tpower
  • 56,100
  • 19
  • 68
  • 100
380
votes
11 answers

What is the difference between NULL, '\0' and 0?

In C, there appear to be differences between various values of zero -- NULL, NUL and 0. I know that the ASCII character '0' evaluates to 48 or 0x30. The NULL pointer is usually defined as: #define NULL 0 Or #define NULL (void *)0 In addition,…
gnavi
  • 25,122
  • 7
  • 21
  • 11
378
votes
5 answers

Create unique constraint with null columns

I have a table with this layout: CREATE TABLE Favorites ( FavoriteId uuid NOT NULL PRIMARY KEY, UserId uuid NOT NULL, RecipeId uuid NOT NULL, MenuId uuid ); I want to create a unique constraint similar to this: ALTER TABLE Favorites ADD…
Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
371
votes
10 answers

Not equal <> != operator on NULL

Could someone please explain the following behavior in SQL? SELECT * FROM MyTable WHERE MyColumn != NULL (0 Results) SELECT * FROM MyTable WHERE MyColumn <> NULL (0 Results) SELECT * FROM MyTable WHERE MyColumn IS NOT NULL (568 Results)
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
361
votes
18 answers

Check if object exists in JavaScript

How do I verify the existence of an object in JavaScript? The following works: if (!null) alert("GOT HERE"); But this throws an Error: if (!maybeObject) alert("GOT HERE"); The Error: maybeObject is not defined.
Yarin
  • 173,523
  • 149
  • 402
  • 512
350
votes
14 answers

Check if a string is null or empty in XSLT

How can I check if a value is null or empty with XSL? For example, if categoryName is empty? I'm using a when choosing construct. For example:
raklos
  • 28,027
  • 60
  • 183
  • 301
331
votes
22 answers

TypeScript filter out nulls from an array

TypeScript, --strictNullChecks mode. Suppose I have an array of nullable strings (string | null)[]. What would be a single-expression way to remove all nulls in a such a way that the result has type string[]? const array: (string | null)[] = ["foo",…
SergeyS
  • 3,909
  • 2
  • 15
  • 17