You may get a bit of bias from this forum since it is a Jeep Wrangler TJ forum (the TJ was produced from 1997-2006). The JK was produced from 2007-2018 (still in production). Again, there will be bias here since it is a TJ forum, but many members here include both a TJ and a JK (such as
@StG58) and they can give you a little insight on both
I'll sum it up like this:
If you want the newer, modern, lower mileage vehicle with all the safety feature, sensors, and bells and whistles, get the JK. Stock versus stock, the JK is more capable off-road than the TJ (though it's also largely dependent on the driver), but not by that much I would say.
If you want the older vehicle with less sensors, less crap to break, and just the bare minimum, get a TJ. A TJ in my opinion is the last of the classic looking Wranglers. They have much less on them to go wrong than the JK, however, they also don't have as much power as the JKs (though it's not bad if you get the 6 cylinder model), but they are much, much easier to fix and work on yourself (if you're into that sort of thing). A clean TJ will hold it's value extremely well, and they can still be found pretty easily with 30k miles or less (though you'll pay more).
You can't go wrong with either, honestly. I suggest driving both and seeing which one you prefer. The JK (even the 2 door) is noticeably larger than the TJ, which is much smaller and more compact.
BTW, the YJ, TJ, and JK chassis designations don't mean anything. They're just terms to identify each generation of Wrangler.