Your First Workspace: Browser, Node & VS Code
Run JavaScript in the browser and with Node.js, organize a small project, and read your first errors.
By the end, you’ll be able to…
- Open the browser developer console and evaluate an expression.
- Load a deferred script from a small HTML page.
- Run a saved .js file with Node.js from its folder.
- Read syntax and reference errors instead of guessing.
01The console is a scratchpad
The browser console is the fastest place to try a JavaScript expression. Open DevTools with F12 or its menu entry, then choose the Console tab. Type 2 + 3 and press Enter. The console displays 5 because it evaluates the expression and shows the resulting value. This is immediate feedback without creating a file.
The console runs in the context of the current page, so it can also reach page features later. When you type console.log("Ready"), the call prints Ready and then reports undefined, because console.log itself returns undefined. That second value is normal. Reloading the page clears the console history, so keep anything worth keeping in a file.
02Load a script from an HTML page
Create a folder named js-practice. Open that folder in VS Code or another plain-text editor so both files appear in the Explorer. Inside it, make index.html and app.js. In index.html, add a script element before the closing body tag. Set its src attribute to app.js and add the defer attribute. The defer attribute lets the browser download the script while it parses the page and run it after the HTML is ready.
Open index.html in the browser and then open DevTools. If the output appears, the browser found the file and executed it. If it does not, check three things in order: the file name, the path in src, and whether you saved the latest edit. A hard reload can rule out a cached copy.
03Run the same file with Node.js
Open a terminal in the js-practice folder and run node --version. A version number confirms that Node.js is installed. Then run node app.js. Node reads the file relative to the terminal's current directory, executes it once, and returns to the prompt. The output should match the browser output.
If Node reports that it cannot find the module, you are probably in the wrong folder or the filename is misspelled. Node does not provide document or window, so browser-only code will fail there. The fact that console.log works in both hosts is a useful reminder that the language core is shared.
04Read the first error, not the last line
A syntax error means the engine could not parse the file, so none of it runs. A reference error means parsing succeeded but a name was used before it existed. The error message names the problem, and the location points to where the engine noticed it. Start with the first line that belongs to your own file.
In the example, the misspelled name mesage produces a ReferenceError. A missing closing parenthesis would produce a SyntaxError before any line ran. Fix one problem, save, and run again. Changing several unrelated lines at once makes it hard to learn which change actually helped.
05Separate normal output from problems
console.log writes ordinary information. console.error writes to the error channel: browsers usually style it red, and Node.js sends it to standard error. Both appear in the same console during development, but the distinction matters when output is redirected to a file or collected by a service.
Use console.error for a failed check or an unexpected condition, not for decoration. Make the message specific enough to act on. A message such as Missing email for profile learner-42 identifies both the problem and the record. A message that says only Error forces the next reader to repeat your investigation.
The ideas worth keeping.
- The browser console evaluates expressions immediately and runs in the page context.
- A deferred script loads with the page, while Node.js runs a saved file from the terminal.
- Read the first useful error location, fix one issue, and rerun before changing more.
Make it yours.
Type and test your code right here in the interactive workspace. Run your solution, check the output, and compare with the worked guide when ready.
Exercise 1: Run one file in two hosts
Create workspace.js with two console.log calls: one prints Coursepodia workspace and the other prints JavaScript is ready. Load it from index.html with a deferred script, then run it with node workspace.js. Provide the contents of workspace.js.
Explore a worked solution
console.log("Coursepodia workspace");console.log("JavaScript is ready");The same file produces the same two lines in both hosts because it uses only the shared language and console. The HTML page supplies the browser context; the node command supplies the Node.js context.
Exercise 2: Fix a file with two failures
One line attempts to print Ready but leaves out the closing parenthesis. A second line prints total, but total is never declared. Write a corrected program that declares total as 42 and prints Ready and then 42.
Explore a worked solution
const total = 42;console.log("Ready");console.log(total);The missing parenthesis is a syntax error, so the original file never runs. After that is fixed, total must be declared before it is used or the program stops with a ReferenceError.
What stayed with you?
Check the ideas while they’re fresh. Your answers stay in this page and feedback appears as you go.
Exercise 1: Run one file in two hosts
Create workspace.js with two console.log calls: one prints Coursepodia workspace and the other prints JavaScript is ready. Load it from index.html with a deferred script, then run it with node workspace.js. Provide the contents of workspace.js.
Coursepodia workspace JavaScript is ready
Keep exploring.
The official references behind this lesson, when you want a second angle or the full details.
One lesson closer.
Reading is a start. Trying it yourself makes the connection.