Interesting use of the function


#1

https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661

Actually, it's not so much in my code not working, which it does, btw, it's more after doing it this way, I'm curious as to why we don't declare the function as:
function greet(name) {
return "Hello" + name + "!";
}
I mean, I get assigning the function itself to the variable, but don't we write functions assigning values to the name called. Wouldn't then, playing devil's advocate, need to first declare the variable that the function is calling or?

So the above example uses
function greet(name){
etc.

wouldn't we have to var greet; ?????


var orangeCost = function (cost) {
    console.log(cost*5);
}
orangeCost(5);


#2

HI you can read more about it here
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions
HOpe that could help you


#3

@cloudmaster82066
What you are referring to
either assign a so-called anonymous function to a variable

var myFunction = function () {};

or you define a so-called named function

function myFunction() {}

( notice NO semi-colon-; )

Read some
== discussions / opinions ==
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1


#4

Thank you both Leon and Wiz! I appreciate it. I hadn't seen assigning a function to a variable in python/pymel, so it sort of threw me. I can do it, and understand it now!


#5

@cloudmaster82066
Here some links to use during your Javascript trip...

Reference

google search
== the Book ==
javascript [your question] site:developer.mozilla.org

== discussions / opinions ==
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
http://javascript.crockford.com/code.html <---JavaScript code-convention
http://javascript.crockford.com/survey.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript
www.developer.mozilla.org/en-US/docs/Web/JavaScript/Guide
http://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript
http://stackoverflow.com/questions/3755606/what-does-the-exclamation-mark-do-before-the-function
http://stackoverflow.com/questions/6260475/how-to-the-operator
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1

The following links may be disabled in the near future !!

Code-Year
https://www.codecademy.com/en/tracks/code-year?jump_to=4fce4211279bae0003006265

teach yourself javascript site:codecademy.com
https://www.codecademy.com/en/tracks/teachyourself


#6

@cloudmaster82066

An object has one or more properties, separated by a comma_,

A property has a property-key and it's associated VALUE

The associated VALUE can be anything from:

•Number
•String
•Boolean
•Symbol
•Object  ◦Function/'Method'
         â—¦Array
         â—¦Date
         â—¦RegExp
         â—¦Math
•Null
•Undefined

Above you have an overview of all data-types.

===== Datatype Array =========
What you must understand,
is that if you ( as an example )
create a array
for the Javascript-Interpreter
you have created an object of the prototype array.
and if you do a google search
javascript array site:developer.mozilla.org
and choose
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
on the left hand side you will see
what information you can gather about the array

PropertiesArray.prototype

Array.prototype.length

Methods ( pre-defined functions for Array operations )

Array.isArray()
Array.prototype.concat()
Array.prototype.every()
Array.prototype.filter()
Array.prototype.forEach()
Array.prototype.indexOf()
Array.prototype.join()
Array.prototype.lastIndexOf()
Array.prototype.map()
Array.prototype.pop()
Array.prototype.push()
Array.prototype.reduce()
Array.prototype.reduceRight()
Array.prototype.reverse()
Array.prototype.shift()
Array.prototype.slice()
Array.prototype.some()
Array.prototype.sort()
Array.prototype.splice()
Array.prototype.toLocaleString()
Array.prototype.toString()
Array.prototype.unshift()


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.