0
0
Javascriptprogramming~15 mins

Running JavaScript in browser console - Mini Project: Build & Apply

Choose your learning style9 modes available
Running JavaScript in Browser Console
📖 Scenario: You want to quickly test some JavaScript code in your web browser without creating a file. The browser console lets you type and run JavaScript commands directly on any webpage.
🎯 Goal: You will learn how to open the browser console, create a simple variable, write a small function, and print output to the console.
📋 What You'll Learn
Open the browser console using keyboard shortcuts
Create a variable called greeting with the value 'Hello, world!'
Create a function called sayHello that returns the greeting variable
Use console.log to print the result of calling sayHello()
💡 Why This Matters
🌍 Real World
Developers often use the browser console to quickly test code snippets or debug web pages without creating files.
💼 Career
Knowing how to use the browser console is essential for web developers and testers to inspect and interact with live web pages.
Progress0 / 4 steps
1
Open the browser console and create a variable
Open your browser console. Then create a variable called greeting and set it to the string 'Hello, world!'.
Javascript
Need a hint?

Use const greeting = 'Hello, world!'; to create the variable.

2
Create a function that returns the greeting
Create a function called sayHello that returns the variable greeting.
Javascript
Need a hint?

Define the function with function sayHello() { return greeting; }.

3
Print the greeting using console.log
Use console.log to print the result of calling sayHello().
Javascript
Need a hint?

Use console.log(sayHello()); to print the greeting.

4
Run all code together in the browser console
Copy all the code below and paste it into your browser console. Then press Enter to run it and see the output.

Code:
const greeting = 'Hello, world!';
function sayHello() {
return greeting;
}
console.log(sayHello());
Javascript
Need a hint?

Open the browser console (F12 or Ctrl+Shift+I), paste all code, and press Enter.