If you are playing SMP, December 1st, 2010 update removed the /home command, and December 3rd, 2010 update added a /kill command, which will kill you upon issuance.
In SSP, there is no 'immediate' way to kill yourself without some additional setup, or handy terrain.
gaming.stackexchange.com/users/1552/Denilson Sá Maia
Just stack about 25 blocks underneath you by jumping & placing a block underneath you (at the height of your jump).
After your stack is built sufficiently high, simply step off the edge to your death.
This stack can be made of dirt, sand, or any block which you have an excess of at the moment.
Once you work out how many blocks you have to stack before the fall will kill you, it will only be a sub-second fall before you're dead.
Also, the stack itself should only take about 10 seconds to build.
Tip:
Use shears to cut leaves from trees, and build your stack out of leaf blocks for a self-destroying structure (the leaves will slowly disappear over time)
in order to prevent your world filling up with random columns of blocks.
gaming.stackexchange.com/users/1777/Keaanu
Lava will also do the trick if you have some nearby.
gaming.stackexchange.com/users/304/JavadocMD
If your goal is to return to the spawn point, then the /home command might do what you want.
gaming.stackexchange.com/users/4402/Nathan
If you are near water just dive in and sink to the bottom...
It will take a while and it will be hard to recover any items you drop.
gaming.stackexchange.com/users/13/ChrisF
Is there a way to kill yourself immediately in Minecraft? Without using normal methods like dropping sand or gravel on top of yourself or letting mobs attack you without fighting back, something like the  kill  command in Quake-like games?
Is there a way to kill yourself immediately?
gaming.stackexchange.com
<minecraft-java-edition>
gaming.stackexchange.com/questions/9904
gaming.stackexchange.com/users/1113/MiffTheFox
Try the home command or try using lava or diving into water. While the /home command has been removed, the /kill command does the same job now. In the game, jumping off 25 blocks can also do it, but lava and water also work the same.
Commands can do this well say users. There are also easy ways in the game