What the nil?


Why do I get the word, "nil" in the terminal at the end of executing my arguments?


Replace this line with your code.


nil is a special Ruby data type that means "nothing". :grin:


Yes, but why does it keep showing at the end of the compiler? It doesn't seem like there should be any reason for it to appear if my code is otherwise correct.



This question pops out from time to time since... this course was published. Someone should add the explanation at the beginning of the course or just delete this feature.

Yes, nil stands for nihil, nothing.

@brianb18 This is the common feature of the REPL's (read - eval - print loop) and it's very helpful (in fact).

Let's say that you have a Ruby console in front of you and you simply want to make some calculations (you are a programmer, a calculator is not for you). So you just type (>> is the input indicator):

>> 28**2
=> 784

Oh, you got the result! Ruby returns the value of the last evaluated expression. Great, right? :slight_smile:

But what happens if you want to print out the result to the console?

>> print 28**2
=> nil

Ok, we got the result, but why there is a nil? Because this is what the print returns.

In the normal environment, the return value of the last evaluated expression is marked by the => (or similar) indicator.

For clarification -> Codecademy is not a normal environment.


@factoradic thanks for the explanation. I thought it might be a bug or I was not doing something right.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.