Picking on Google here, their most valuable part by far is injecting ads into search. Most agree their search is nothing special, getting worse even. We've seen tens of companies write good enough search engines. You could write one 10x better tomorrow and still likely fail. Their code is not the secret sauce - their user lock in is.
A lot of the same could be said for FB.