Day 4 of Javascript: key concepts about return, block scope, global scope, and how to get user input
What is the return keyword
The return statement stops the execution of a function and returns a value. It is used to access the value calculated inside a function from outside of it and to prevent the function from continuing to execute after returning a result.
What is Block Level Scope
A variable declared inside a block is considered block-scoped. It cannot be accessed from outside that block when using let or const. Example of using return with block scope: function add(a, b) { let total = a + b; return total; } add(10, 20)
What is Global Level Scope
A variable declared outside any block or function is globally scoped. It can be read and modified both inside and outside functions or blocks. Example: let total; function add(a, b) { total = a + b; } add(10, 20); console.log(total)
How to get user input
Using the prompt() method, information can be requested from the user through a dialog box. prompt() is a built-in function that displays a message, a text field, and OK and Cancel buttons. It always returns a string if the user presses OK after typing text, returns an empty string if they press OK without text, and returns null if they press Cancel or close the box. Example of use: let a = prompt(enter the age); if (a >= 18) { console.log(Eligible to vote); } else { console.log(Not eligible to vote); }
At Q2BSTUDIO we are a custom software and application development company specialized in modern solutions for businesses. We offer custom software, custom applications, and artificial intelligence projects designed to improve processes and generate value. Our services include cybersecurity, AWS and Azure cloud services, business intelligence services, and AI consulting for companies. We design AI agents, Power BI integrations, and analytics platforms to support data-driven decision-making. If you are looking for a technology partner to develop custom software, boost artificial intelligence in your organization, strengthen cybersecurity, or migrate to the cloud with AWS and Azure cloud services, Q2BSTUDIO can accompany you from the idea to production deployment with scalable and secure solutions.


