why in VSC there are no results in Output?

Daulet Amandikoff 1 Reputation point
2022-04-13T13:16:28.183+00:00

Why in VSC there are no results in Output?
Working with a Java script, for example, in the browser console or in Node JS, I see the result of each code. In VSC, in the output section, there are no results as, for example, others have. How can I display the results of my work in the output section?
I would like to display in the output section as attached screenshots.
I have attached two screenshots. In the screenshot at number 14, we see the result in the output section, in the second screenshot er.1 we don't see the result in the output section. How to make the output section show me the result of the work performed as in the screen at number 14. Thank you in advance.

Community Center Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-04-13T14:43:38.453+00:00

    JS is an interpreted language that doesn't really have an integrated debugger. Hence the easiest way to debug it is to print stuff to the console window as you step through code. For a compiled language this doesn't work because the code is compiled and may or may not run any time soon. These types of languages have an actual debugger that you can run to debug your code.

    Without knowing anything else about what you're trying to do I would recommend against the "printf"-style debugging you're used to in JS. It simply isn't needed in a good IDE like Visual Studio. To debug your code set a breakpoint (F9) on the line of code you want to stop at. Run your code in the debugger (F5) and when that line of code is hit you can then step through (F10/F11) the code to verify the behavior, check the state of variables, etc. There is really very little benefit in output window debugging. It requires too much effort and modification of code when you can do much more without any code changes.

    Having said that you can print to the program's output window at runtime using the IO functions of the language. You mentioned VSC so I assume you're using C/C++. If you're using C then printf is how you do it.

       printf("Will appear in output window at runtime");  
    

    In C++ you can still use printf but the preference is to use cout instead.

       cout << "Will appear in output window at runtime";  
    

    But all this assumes you're building a console application such that there is an output window. Technically a nodejs is a console app and therefore would behave similarly. However the console window in the browser is really a debugging window and not an output window.

    In a language like C/C++ the debugger's Output window is only visible while running in a debugger attached to the IDE (equivalent to the browser's console window). To write to the debugger's output window you would have to call to the OS because debugger's are OS specific. In Windows you use the OutputDebugString function.

       OutputDebugString("Will appear only in the debugger's output window while debugging");  
    

    In many cases the libraries you're using define a TRACE macro to make this a little cleaner.

       TRACE("Will appear only in the debugger's output window while debugging");  
    

    So, in summary, if you want the user to see the output use printf/cout. If you only want it for debugging purposes then: a) use the debugger commands instead, b) use OutputDebugString.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.