It can be used to say that you will do something although you know you should not do it. It expresses confusion and is a short way of saying what the hell.
Guy 1: What the heck? A rock appeared from nowhere! Guy 2: Crazy, right? Guy 1: I know!