If you are using a Mac, you will notice that your screen’s brightness is auto-adjusted if you have that option enabled… just like in your smartphone. If you ever wander how they to it or where is the brightness sensor located take a better look to your mac.
Did you saw it? Probably not … but your look again on top of the display, around your front camera you will see some extremely small holes on both sides. One in the right of the camera is the brightness sensor.
You can easily check that by holding your hand on front of that area or (if it’s night) using a flashlight.