Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Using Functions | Functions
New Script JS
course content

Contenido del Curso

New Script JS

New Script JS

1. Basic Controls
2. Functions
3. Loops
4. If-Else Statements
5. Challenges

book
Using Functions

Why Use Functions?

Repeating code makes programs long and hard to maintain. Functions let you group commands into a reusable block, reducing repetition and making your code cleaner.

How to call Functions?

To call a function, simply use its name followed by parentheses, placing any required arguments inside those parentheses.

In the example below, the greet function is called on line 5 by adding parentheses to its name and passing "Alice" as the name argument.

A Simple Function Example

12345
function greet(name) { console.log("Hello, " + name + "!"); } greet("Alice");
copy

Here’s what happens when you call greet("Alice"):

  1. JavaScript looks for the function named greet.
  2. It passes the string "Alice" as the argument for the parameter name.
  3. Inside the function, the console.log statement concatenates "Hello, ", the value "Alice", and "!" to create the full greeting.
  4. The final message "Hello, Alice!" is then printed to the console.
Tarea

Swipe to start coding

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 1
js

ninja.js

html

index.html

js

preset.js

toggle bottom row

book
Using Functions

Why Use Functions?

Repeating code makes programs long and hard to maintain. Functions let you group commands into a reusable block, reducing repetition and making your code cleaner.

How to call Functions?

To call a function, simply use its name followed by parentheses, placing any required arguments inside those parentheses.

In the example below, the greet function is called on line 5 by adding parentheses to its name and passing "Alice" as the name argument.

A Simple Function Example

12345
function greet(name) { console.log("Hello, " + name + "!"); } greet("Alice");
copy

Here’s what happens when you call greet("Alice"):

  1. JavaScript looks for the function named greet.
  2. It passes the string "Alice" as the argument for the parameter name.
  3. Inside the function, the console.log statement concatenates "Hello, ", the value "Alice", and "!" to create the full greeting.
  4. The final message "Hello, Alice!" is then printed to the console.
Tarea

Swipe to start coding

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 1
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt