Contenu du cours
Introduction to JavaScript
Introduction to JavaScript
1. Getting Started
First Javascript Console ApplicationChallenge: Showing some OutputChallenge: Outputing Multiple LinesDealing with NumbersChallenge: Working with NumbersChallenge: Calculating the Speed of a CarChallenge: Calculating Area of a TrapeziumOutputting Multiple ValuesChallenge: Consoling Meaningful OutputHow to Use Comments in Javascript?Challenge: Adding a CommentMulti-Line CommentsChallenge: Commenting out CodeWhat Is JavaScript anyway?
2. Manipulating Data
Storing DataChallenge: Declaring a VariableChallenge: Accessing Data From a VariableChallenge: Fixing Variable NamesChallenge: Reassigning a VariableConstantsChallenge: Declaring & Using ConstantsPerforming Arithmetic On VariablesChallenge: Making a Salary CalculatorChallenge: Adjusting Salary with a BonusExploring Primitive Data TypesChallenge: Declaring a Boolean ValueHow different Data Types InteractChallenge: Concatenating StringsChallenge: Creating User Profile & Activity Details
3. Conditional Statements
Comparison OperatorsChallenge: Checking Age EligibilityThe `if` StatementChallenge: Weather-Based Outfit RecommenderChallenge: Even or OddNested Conditional StatementsThe `else` ClauseChallenge: Improving Even or Odd CheckerChallenge: Temperature AdvisorThe `else if` ClauseChallenge: Grade Categorizer` AND` Logical OperatorChallenge: Checking if a Number is Even and PositiveOR Logical OperatorChallenge: Accessing Control System
4. Mastering Functions
What Are Functions?Challenge: Simple FunctionChallenge: Calculating the Speed of a CarScopesPassing Data into FunctionsChallenge: Fixing the Speed FunctionChallenge: Improving the Grade CategorizerTask: Defining a Compound FunctionReturning Data from FunctionsDefault ValuesChallenge: Email Auto-Responder with Default Parameters
5. Exploring Arrays
What Are Arrays?Challenge: Defining An ArrayChallenge: IndexingAdding Values to an ArrayChallenge: Pushing Elements to an ArrayRemoving Elements from an ArrayChallenge: Practicing `pop` & `shift`The `length` PropertyChallenge: Counting ElementsThe `includes` MethodChallenge: Searching for Animals in the Zoo
Returning Data from Functions
We can return any kind of value from a function using a return
statement.
function sum(a, b) { return a + b; } let result = sum(10, 15); console.log(result); // Output: 25
General Syntax
The general syntax of a return statement is
js
Where <value>
is optional. If no value is provided, the function returns undefined
:
function exampleFunc() { console.log("In the Function"); return; } let result = exampleFunc(); console.log("Return value if nothing is returned:", result); // Output: undefined
How It Works?
The return statement stops the execution of the function, and returns to the point in code the function where it was called. Therefore, any code after return
is ignored:
function exampleFunc() { console.log(1); console.log(2); return true; // Execution stops here console.log(4); // Ignored console.log(5); // Ignored } console.log("Before Function Call"); console.log(exampleFunc()); // Output: true console.log("After Function Call");
1. What will be the output of the following code?
2. What happens if a function has a return statement with no value?
3. What will be the output of the following code?
4. In the following code, what will be the value of result
?
Tout était clair ?
Merci pour vos commentaires !
Section 4. Chapitre 9