javascript – Render solid objects in a canvas game?


I have a small HTML canvas game that I’m developing. I need an efficient way (NO APIs) that I can render a solid object that the player can’t go through. I don’t want a bunch of ‘if’ statements that check if the player is inside of it, and if it is, where will it go when it’s detected inside? So I would have to do four if-then statements for each wall of it, and it doesn’t seem very efficient. I don’t want to use an API or any external code, but is there something that I’m missing here? I’m sorry if this is a bad question, but I really just can’t figure it out. (I know I also asked this in another community, but I need answers as soon as possible) Thanks in advance!