I don’t know if my understanding is correct but I always thought of a switch in contrast to a network hub. A hub broadcasts incoming packets to all its ports while a switch keeps a table and broadcasts only to the port that MAC is plugged into. That table is likely called a “routing table”, which probably drives some confusion. I always thought of a router as an internet connected switch. In addition, I always thought of a modem as something that can speak the language of the line (phone lines originally) instead of just the network protocol.
I’m not a network pro and these concepts could be totally wrong in my mind. Not sure why I’m spewing them out, other than to give myself something to solidify in the future.
You're mostly there - your hub definition is spot on - it's basically an electrical repeater and doesn't inspect the packet in any way* and operates at half-duplex.
Switches (specifically Layer 2 switches) will send broadcast frames to all ports*, but traffic that is unicast to a specific MAC address will only be sent to the port where that MAC address was learnt. To keep track of the MAC address to port mappings, a switch will have one or more "forwarding" or "MAC-address" tables.
Routers (and Layer 3 switches) are not necessarily Internet connected, but will mostly be seen in larger networks. Being mostly Ethernet-based these days, they maintain two tables - an ARP table (mapping IP Addresses to MAC Addresses) and a routing table (mapping IP prefixes/routes to destination IP addresses). When an IP packet comes into a port, the router will consult it's routing table and find the most specific route that matches the destination of the packet. From the destination IP of the route, it will then determine the egress interface that it should send the packet towards, then use the ARP table to work out the destination Ethernet MAC address for the Ethernet frame it will construct to transport the IP packet in on it's way to the next-hop router.
* During the early 00s there were "Dual-Speed Hubs", which were basically two hubs (one 10Mbps, one 100Mbps) joined together internally via a two-port Ethernet switch. Fortunately the price of 100Mbps Ethernet switches kept falling and they weren't around too long.
* Provided those ports are all members of the same broadcast domain/VLAN
I’m not a network pro and these concepts could be totally wrong in my mind. Not sure why I’m spewing them out, other than to give myself something to solidify in the future.