Definitely not at the 40, because of how hard a field goal at the 40 is (edit: see Philip's answer for that calculation, I'll not duplicate that here). I will say that the graph in that answer is a bit old, 2014, and unfortuantely that site isn't updated anymore, but it's still close enough for that answer to be right.
See the JAX-MIA game from 9/24/2020 for a good example; here, there is a 1st and 10 on the 48, EPB (Expected Points Before the play) of 2.3, and a 2nd and 5 on the 43, EPB 2.5. Then the following first and 10 on the 37 has an EPB of 3.1; that's above the value for a field goal even if it had a 100% chance of making it. Of course, the Dolphins scored a touchdown on that drive, but it's the right call to press on whether that succeeded or not.
For a bit of detail over Expected Points, you can read this older ESPN article; but in short, expected points are the number of points that are statistically predicted to be scored from that down and distance from the average team - not from a specific team, so the Chiefs probably score a bit more than the Bears from a particular yard line; it's not perfect, but it's decent.
This can be used to make decisions; such as, on 4th and 1, do I go for it, or kick a field goal / punt? If the expected points from a particular down and distance is greater than three, then it's probably better to go for it on average than it is to kick the (3 points or less) field goal, or punt; but in the latter case, you need to take into account the expected points for your opponents starting on that line also. Again, it's not perfect (as it's not team specific), but it's a good metric and as good of one as we have.
The other consideration I would suggest, beyond the pure numbers, is that defenses tend to tire out more easily than offenses. As such, you're better off forcing their defense to stay on the field longer. The NFL is unique in having players only play one side of the ball, and that makes this a much bigger concern than in other sports.