Skip to content

Latest commit

 

History

History
23 lines (21 loc) · 3.51 KB

program-debug-error-handling.md

File metadata and controls

23 lines (21 loc) · 3.51 KB

Simple program in JavaScript that prints "Hello, World!" to the console:

console.log("Hello, World!");

You can run this program by opening the JavaScript console in your browser (usually by pressing F12 or right-clicking and selecting "Inspect Element" and then selecting the "Console" tab), and pasting the above code into the console and pressing enter.

You can also use Node.js to run JavaScript code outside of a web browser.

In order to write and run JavaScript code, you will need a text editor, such as Notepad, Sublime Text, or Visual Studio Code, and a web browser or Node.js environment.

You can also use the JavaScript console to debug your code by adding the following line before the console.log statement

debugger;

Here is an example of basic error handling in JavaScript:

try { // code that may throw an error let x = y; // y is not defined } catch (error) { console.log(error); // Output: ReferenceError: y is not defined }

And here is an example of working with strings and numbers in JavaScript:

let firstName = "John"; let lastName = "Doe"; let fullName = firstName + " " + lastName; console.log(fullName); // Output: "John Doe"

let a = 10; let b = 20; let sum = a + b; console.log(sum); // Output: 30