Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Function, loops js (Lesson 3 with Hassan)
Hanna
Hanna

Posted on • Edited on

     

Function, loops js (Lesson 3 with Hassan)

FUNCTION

A JS function is a block of code designed to perform a particular task and is executed when "something" invokes it (calls it).
We can submit 0, 1, or more parameters to a function.

ex.
function functionName(parameter1, parameter2, parameter3) {  // code to be executed}
Enter fullscreen modeExit fullscreen mode

FUNCTION & RETURN STATEMENT

The return value is "returned" back to the "caller".

ex.
function myFunction(a, b) {  return a + b;}console.log(myFunction(5, 6))// Function returns 11
Enter fullscreen modeExit fullscreen mode

LOOPS

Loops are used in JS to perform repeated tasks based on a condition. Conditions typically returntrue orfalse when analysed. A loop will continue running until the defined condition returnsfalse.

FOR LOOP

for ([begin]; [condition]; [step]) {   // statement}
Enter fullscreen modeExit fullscreen mode
ex.
for (let i = 0; i < 10; i++) {    console.log(i)}
Enter fullscreen modeExit fullscreen mode

WHILE LOOP

The while loop starts by evaluating the condition. If the condition istrue, the statement(s) is/are executed. If the condition isfalse, the statement(s) is/are not executed. After that, while loop ends.

while (condition){  statement(s);}
Enter fullscreen modeExit fullscreen mode
ex.
let i = 0;while (i < 10) {  console.log(i);   i++;}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Beginner Web Developer FullStack Open Source
  • Education
    Nackademin
  • Work
    Student
  • Joined

More fromHanna

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp