🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)
🕵️ SicherheitslückenWhat continuous operational resilience looks like under DORA(09.09.2026 um 17:53 Uhr)
🔧 AI Nachrichten OpenAI seeks tougher AI rules. CIOs may feel the ripple effects(10.09.2026 um 12:11 Uhr)
🔧 AI Nachrichten Mistral valued at €21bn after €3bn Series D funding round(08.09.2026 um 10:19 Uhr)
🪟 Windows TippsWindows XP's Cursor Indicator Is Getting a Windows 11 Refresh(25.08.2026 um 13:00 Uhr)

🔧 Programmierung 🕛 vor 1 Jahr 2 Min Lesezeit
0

Functions as First-Class Citizens in JavaScript

↗ Quelle (dev.to)
🗣️ Stimme:




What is a First-Class Function?



First-Class Citizens’ means that functions can be used in the same way as other data types. It implies that functions can be assigned to variables, passed as arguments to other functions, and returned as values. This is a crucial concept in functional programming as it allows us to write more modular and reusable code.




  • Assigned to variables


  • Passed as arguments to other functions


  • Returned as values from functions



Here are some examples of using functions as first-class citizens in JavaScript:





  • Assigning Functions to Variables: You can assign functions to variables and use the variables as you would with any other variable.






Example:






CODE
const add = function(x, y) {
return x + y;
}
console.log(add(5, 4)); // Output: 9
console.log(typeof(add)); // Output: function








  • Passing Functions as Arguments: You can pass functions as arguments to other functions. This is useful for designing higher-order functions or callback functions.






Example:






CODE
function greet(name, callback) {
const message = "Hello, " + name + "!";
callback(message);
}

function logMessage(message) {
console.log(message); // Logs "Hello, Nozibul!"
}

greet("Nozibul", logMessage); // Logs "Hello, Nozibul!"








  • Returning Functions as Values: A function can return another function from within. This is useful for creating functions that can be used in subsequent operations, such as currying functions.






Example:






CODE
function add(x) {
return function(y) {
return x + y;
};
}

const addFive = add(5);
console.log(addFive(3)); // Output: 8








  • Storing Functions in Arrays: Functions can be stored in arrays just like any other value.






Example:






CODE
function add(a, b) {
return a + b;
}

var arr = [];
arr.push(add);
console.log(arr); // Output: [ [Function: add] ]
console.log(arr[0](2, 5)); // Output: 7








  • Storing Functions in Objects: Functions can be stored as properties of objects.






Example:






CODE
function add(a, b) {
return a + b;
}

var obj = {
sum: add
};

console.log(obj.sum(5, 7)); // Output: 12
console.log(obj); // Output: { sum: [Function: add] }






These examples demonstrate how functions in JavaScript can be treated as first-class citizens, allowing for powerful functional programming paradigms.

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Sam Altman calls GPT-6 Astra rollout ‘messy’ as enterprise users wait for access
1 Quelle
OpenAI seeks tougher AI rules. CIOs may feel the ripple effects
1 Quelle
Mistral valued at €21bn after €3bn Series D funding round
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Functions as First-Class Citizens in JavaScript

Thematisch verwandte Begriffe: Functions, FirstClass, Citizens, JavaScript · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...