I'm new to JavaScript and learning it for a week now. I had applied for an internship in different companies and I was called yesterday for an interview. They asked me some questions and for this one particular question, I had no clue. Can someone provide me the solution or help me clarify this proxy topic.
What is the solution to this Question?
Please write a simple log function that will proxy a string argument to console.log() *
If I were asked this question I would understand "that will proxy a string" to mean "that will pass on a string ... in a controlled way". Wikipedia writes about the Proxy pattern:
So in this case you would verify that the argument is a string, or another interpretation could be that you would convert a non-string to string before passing it on to
console.log
. So I think the following two answers would be OK:Or: