Spoilers for the end of the movie:
At an early scene of the movie, we see that the demon Valak reveals his name to Lorraine and that the latter scribbles his name in her bible. Later, she hears the riddle from old Bill, where she realizes that if they knew the demon's name, they would have power over him, which they do -> that's how they beat him.
But I don't understand. Why would the demon reveal his name, since it was the only way to be defeated?