Weekly questions to consider when creating your posts. These questions are a jumping off point to asking your own questions, pose new ideas, and provide explanations and examples backed by careful analysis. Apply class concepts, terms, and theories too. Refer to Assignment 12 for additional details.
- What is a function in JavaScript, and what do all functions have?
- What does calling a function do?
- What does it mean to pass a function arguments, and what does that do?
- What is the purpose of the return keyword in functions?
A function in Javascript is a set of codes used to perform tasks, which contains some calculated values. Javascript has a total of three functions, which are function declaration, function expression, and anonymous function. Calling a function refers to giving the computer an instruction through code to let it run the instruction given by the code. Pass a function arguments refers to the process of passing parameter values to corresponding formal parameters when the program is running, and then implementing data processing in the function. Its use is to substitute the calculated value into the formula for calculation. The purpose of the return keyword in functions is to end the execution of instructions for this function and return its control to the calling function.
Hey Jinzhou,
When reading your response I noticed that you talked about the different versions of functions being declaration, expression, and anonymous. When doing my own search I didn’t even know there was a difference. If I wanted to keep learning on after the basics of coding on JavaScript, I’d say that’s probably something I should know. Also I just wanted to say that you could point out that function make coding easier and quicker because they are for basic tasks and allow for less need to type out longer strands of code.
You post was very informational. I also did not know there were three functions of JavaScript. JavaScript reminds me of excel and how we input data to then run outputs or calculations.
Hey Jinzhou, I thought you did a great job explaining JavaScript codes and went into great detail of it in order to help describe what was being asked. Nice job!
In JavaScript there are functions that complete certain tasks or perform certain operations for you. These functions allow the user to set up operations or calculations much quicker for usually more common tasks. One thing that all functions need to have are brackets to hold all of the information in and let the computer know that there is nothing else there. These functions will only work though when someone or something invokes it by calling on it. Calling on the function is when a person tells the computer to start running the code that was entered.
Function arguments are the values passed around within a function. Saying pass around in this situations refers to the previous line of coding interoperating the information and giving the new interpreted information to the lower line of code. This allows functions to be able to run from one line to the next in a situation like trying to complete a math problem on JavaScript. If you are trying to answer 4+2*4 and the data isn’t being passed around in an appropriate order, the problem will be wrong or not fully answered and put together. To be able to finish a line of code you need to use the return keyword as well as the brackets to tell the computer to not go farther or even allow you to make a separate sequence on the same page.
Hi Justin Bonfiglio,
I think your analysis of functions in javascript is in place. In fact, functions are a very important part of javascript, which involves inference and participation in all decision-making in javascript. I think your 4+2*4 example is very interesting, because many people who are new to programming will not understand the principle of programming, and often appear garbled characters. Your answer has solved many beginner’s doubts.
Hi Justin,
I like how you describe javascript functions as “complete certain tasks or perform certain operations for you” One thing I forgot to mention in my post is that functions need brackets to hold the information all in one, so the computer knows what to focus on. Describing a function as telling a person to run a code is the best way to describe a function. As a beginner javascript, your example of 4+*4 helps me understand what a return keyword is and how important and how to use it properly during coding.
Hi Justin, the way you described functions was great. I found that it was easy to understand and for someone that would not know what functions are, they could pick up on it after reading that. One thing I find interesting about functions and coding in general is how many people think that computers are intelligent on their own. However, we need to tell them what to do in order to run properly, just like how you mentioned the return keyword.
A function in Javascript is a set of goals to be completed or calculate numbers quicker. One of the examples from class I liked was “functions allow our code to be more maintainable an reusable!” All functions in javascript need an input, relationship, and output such as name, “passed zero or more pieces of information,” and “return a value” I believe calling a function in javascript is just one big piece of code bundled together. According to a site called launch code education, “Functions are data and therefore can be passed around just like other values. This means a function can be passed to another function as argument. This allows the function being called to use the function argument carry out its action.” My thoughts on this are if you create a function, you can reuse the function on a different project to save time because scripting takes a lot of time and patience. The “return” keyword allows you to send back data to the function you created in the first place pretty much ends the execution and goes back to the function.
Hi Montajim,
I really liked how you referred to examples we did in class as well as external sources in your post. I think it’s interesting that you called a function a “set of goals”. A function is designed to be a repeatable chunk of code with a purpose, either to modify a value, compute a math statement, print a string, or something else, and it definitely has a goal it wants to achieve. I agree with you that functions also our code to be more maintainable, and it saves a lot of time to code a function once and then call it over and over again.
Hi Montajim,
I enjoyed reading your post. I also like that functions help our code to be more maintainable and reusable. My experience using Excel has taught me that functions are your best friend. I used to spend lots of time retyping numbers into Excel, but once I learned a few easy functions, I became way more productive. Coding involves so much information, so having reusable, time-saving tools is a great thing.
Hi Montajim,
You did a terrific job at explaining what functions are and how they are used in JavaScript. And yes, I completely agree with you in terms of how long it takes to thoroughly understand how to create functions, but I can safely say that I am grateful that this class helped me appreciate what JavaScript can do in the digital world and how it can be super effective in supporting future business ideas.
A Javascript function groups a combination of statements together and makes your code reusable. Functions can also be applied to math problems, such as finding the sum of a group of numbers or solving for distance in an equation. The majority of work will be contained in functions while the main program is just handling input and output. Every Javascript function is the same in that they all are passed zero or more pieces of information, have a name, and, normally, return a value. Excel functions, on the other hand, will return a value no matter what. There are a few extra steps when writing functions in Javascript. They require more parentheses as well as brackets. Similar to variables, we can’t just name, or define, our function and leave it like that. It needs to be called. Normally, the function call is the name of the function, followed by more parentheses–for example, sayHello() . By officially calling the function, it tells Javascript to execute the code.
Hi Madeline! This is a great explanation of Javascript functions. I think it is important how you compared the differences to Excel functions. Javascript functions are great for calculating values and performing a task. Knowing the steps that it takes to make this possible allows code to be more readable for me.
Hi Madeline, I liked learning about functions but the more you start to do them the more you realize it’s common sense because it’s math. It’s also interesting to see how complex you can get with functions and how endless the possibilities that functions have in the field of coding. Great work breaking down what the represent in the context of JavaScript.
Functions in JavaScript allow users to code one block of code designed to perform a particular task, and then call that code as many times as needed. All functions have brackets to contain the function code, and functions can be called by typing the function name followed by () and a semicolon. Functions can hold any amount of code, but efficient functions should not be too long. Functions can contain if, while, and for statements. Functions can be passed arguments known as parameters; parameters can be modified and are placeholders for different arguments. A function will take a parameter and either modify or use it for calculations. Depending on the type of function, sometimes the function will return an output, whether computing a value or returning a string, but it doesn’t necessarily have to. For example, if you call a function designed to modify an existing value that is passed an argument, it might not return anything, but if you output the value in the console, it will be different than it originally was. For functions that return a value, that value can be stored in a new variable. The return keyword should always be at the end of the function because the computer will not run code after it recognizes the return keyword.
The return feature is available in almost every programming language. Developers can use the return keyword with or without a value. If a value is specified, it will be returned to the caller. Otherwise, a null value will be returned. The return statement ends the function execution and specifies a value to be returned to the function caller. When a return statement is used in a function body, the execution of the function is stopped. If specified, a given value is returned to the function caller. The return statement is affected by automatic semicolon insertion (ASI). ;
A function in JavaScript is a way for a person to organize the codes they have created, maintain them, or even reuse them. The functions are putting together statements. Those statements show the relationship between input and output. The functions all have parentheses. brackets, a name, they also are passed zero or more pieces of information, and sometimes turn a value. The calling function is when we call the function we named. To pass a function argument means passing the value to the function. The purpose of the return keyword is to return data back to the called function we started with.
An example of all of this is:
function myFunction(a, b) {
return a * b;
}
I think…I hope I explained this well. This has been the most difficult part of this course for me. Well along with the Exams.
A function in JavaScript is a block of code designed to perform a specific task. All functions in JavaScript have a function name, a set of parentheses, and curly brackets that contain the code to be executed. Calling a function executes the code inside it and returns a value. To pass a function arguments means to provide values or variables to the function that it can use to perform its task. This allows for flexibility and reusability of the function. The purpose of the return keyword in functions is to specify the value that the function will return when it is called. Without a return statement, the function will execute but not provide any value back to the calling code. The return statement can also be used to terminate a function prematurely if necessary.
I am responding after exam 3 and reading your post help me know I got some questions correct. Specifically the explanation of function arguments because they pass a function. I could not remember in the middle of the exam.
Hi Shivam,
You have clearly explain how the JavaScript work and explain the “return” meaning for the code.
In JavaScript, a function is similar to a procedure, which is a set of statements that performs a task or calculates a value; however, for a procedure to qualify as a function, it must take some input and return an output with an obvious relationship between the input and the output. When you call a function, you are instructing the computer to carry out that set of actions. A function definition can be placed anywhere in your code; in some ways, it exists independently of the code that surrounds it. It makes no difference where you put a function definition. Because functions are data, they can be passed around just like any other value. This means a function can be passed to another function as an argument. This allows the function being called to use the function argument to carry out its action. A return statement ends the execution of a function, and returns control to the calling function. Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function.
Hi Assia! You did a great job explaining the JavaScript functions. I appreciated the reference of a function to a procedure. It absolutely helps to add that as a point of reference/understanding. As an individual that did not have experience with coding prior to this class I find references to non coding items to be especially useful. Did you have any experience with coding prior to this class?
A function name: The name of the function is what is used to call it.
The definition of any function’s input arguments is enclosed in a set of parentheses.
The code that will be run when the function is invoked is surrounded in a set of curly brackets.
When a JavaScript function is called, the code inside the function is executed and, if any values are returned, they are passed back to the calling code. Throughout a program, functions are reusable chunks of code that can be invoked at different points. Any necessary input values (often referred to as arguments) are provided to a function when it is called, and the function uses these inputs to carry out the specified purpose.
hello Yi-Lun,
Functions are very useful in programing because in designing we end up using the same process many times. For example writing one function to calculate interest payments should be only written once and call it when needed in a banking program. Thus, many programs or websites use similar functions related to their industry multiple times in their system.
When operating in JavaScript, an user might use a function. A function is a way they can organize their code to make it easier to create, maintain, and reuse. When using functions, they must have a name, the function must be passed through zero or more pieces of information, and the function returns a value. To keep functions efficient and less confusing, users might want to avoid repeating code over and over again unless needed. A simple function could look as basic as
function HelloWorld() {
alert(“HelloWorld”);
}
As you can see, a function must begin with the function keyword, then you have the function name (HelloWorld in this case) followed by parentheses, then the code in the function runs when the function is called. Calling a function just means that you write the function name followed by the parentheses again, but this time outside the initial function. Function arguments are when a function call will contain data that is passed into the function. A quick example would be function sum(num1, num2) {
alert( num1 + num2); }
sum(4, 5);
This function call would have the number 9 appear as the function arguments are added together. Return keywords can also be used to send back data to whatever initially started the function. When the function meets the return keyword, it will stop doing everything at that point and no code after return will run.
Hey Aidan,
I enjoyed reading your weekly blog post and definitely agree with your interpretations of functions and how they are exemplified. While using Javascript, as i stated previously to one of our fellow classmates, at first it was definitely a adjustment for me especially when I would implement blocks of code or functions and debug it to realize that I was not completely right. It took a few tries and a breather to finally get the results I intended on getting initially.
When it comes to JavaScript this is a coding language that is made for users to interact with websites or games. JavaScript has these things called functions where it enables interactions with the software. In these functions, you have variables that are the key to a function. All functions in JavaScript have things like names, bodies, and symbols. Functions in JavaScript can be defined in multiple ways, including using function declarations, function expressions, and arrow functions. “They can also be nested, meaning that one function can call another function to perform a specific task”. All functions in JavaScript have a name, parameters, a body, and an optional return statement. Understanding functions is essential for understanding difficult applications and building reusable code. For now this is just the surface of knowledge for Javascript, as there are plenty of more things to learn about putting together a function, or just creating an interface using this tool / language.
In JavaScript, we use functions in order to accomplish specific operations. Brackets are what we use in order to hold every bit of information in and so that the computer can detect that that is all there is. However, the only way we can actually get these functions to work is to make sure the computer is aware of when to start running the code. The way we do this is by calling on the function. The return keyword allows us to transit data back into our function from the beginning. Functions are excellent to use mainly because we do not have to worry about constantly typing the same thing over and over again in order to solve for distance or even if we want to sum up a big group of numbers. It feels very relatable to Excel because we know that we can sum numbers in Excel the same as in JavaScript. Statements in functions can contain for, while, and if statements and it is also very important to remember insert the return keyword at the end of the function otherwise the computer will stop running the code after it acknowledges this keyword.
Hey Nicholas,
I enjoyed reading your response. Many of the functions used in javascript have a specific purpose which definitely caused confusion for me while trying to get my intended results of the functions or blocks of code. I am not sure if this is similar to what you encountered when trying to figure out HTML and Javascript but it definitely was an adjustment for me when trying to implement the right symbols, functions and keywords in the software. Although it took a few tries, the consistent effort allowed me to finally acquire my desired results, I am assuming this was the same with you as well.
Hello class,
JavaScript works with functions. Functions are defined as set of codes designed to perform a particular task when something invokes or calls it. Functions must be given a name followed by parentheses. Within these parentheses parameters may be included. functions arguments are these values received by the same function when it is called. However, functions can also be called when an event happens or automatically. Often, functions return a value after they are called. But I asked myself why are we using functions? Because functions can be used and reused as many times as needed. There is no need to rewrite codes when the same process has to be repeated we can just simply call the function to perform this process. Moreover, functions can shorten our codes because it is used as a variable value. Functions are very useful tools in designing programs or websites.
Yes, you are correct. We can also use functions to create our own custom formulas in Microsoft Excel, and overall knowledge of JavaScript functions can make our Excel skills better.
Other than functions are very popular, functions in JavaScript have an important place. Function groups up statements and can be reused to make coding less time-consuming. The function can take provided information, do various types of calculations with the information, and return the result. It is almost like an Excel formula, but unlike Excel, you can build the function as you like. In a way, function is just a math problem, like the ones we did in regular math class. Unlike a regular math problems, we introduce variables which stored numbers, we create a function to receive a sum of two variables and function adds numbers and returns a result for us. For easier use, later we can change just on number and use the same function to receive a new result. We can start writing the function code with the keyword function following with the actual name of the function.
As we continue to develop our knowledge through learning more about coding and the different terminology that goes along with it, it is important to ensure that we are taking the time to comprehend new topics. When it comes to coding, a function is defined as something that performs a specific task or operations. Usually these functions come in sets of different statements, and can calculate values. When you have a function you can also “call” a function. Calling a function applies that same function to more than one object within the code. For example: You can create one function for a specific object, and then call that function to another object as well. This all revolves around having an input in order to return an output. The bigger picture of functions is that they help group related code, in order to make it more organized. When a code is more organized it allows the programmers to identify problem areas within the code or even emulate it in order to code for something else!
In JavaScript, a function is a block of code that performs a specific task. They are illustrated as “functions” on the code itself. Each function has a name that gives the function identity and a body that defines what the function does using brackets. The code itself would go inside these brackets. When a function is called in JavaScript, the code inside a function is executed by switching to the function’s code block to do so. After execution is complete, the program runs and conducts as usual. Parameters can be added when a function is called upon. Function arguments are values provided as data for which the function can operate effectively. It allows you to understand and differentiate results based on their context. The “return” keyword is used to show the function’s output or result. For example, if I put in a function trying to multiply for 2 * 2, my return function would be “4” because of the function.
A function in JavaScript can be described as a set of statements that performs a task and calculates a value. In order for a procedure to qualify as a proper function, it will take certain amounts of input. Calling a function is also referred to as invoking a function, an is used to pass the control of the program to get to the required function. The function then returns the control of the program back to the main program. To pass a functuion argument, arguments are referring to the values that could be passed to another function. The purpose of this is to provide use as input information. The return keyword in functions is meant to cause your function to exit and lead its value back to the caller.
A function in java script is the operation or task that you are asking the program to complete. A function contains a mathematic question or just a way of answering a certain problem. A function is made by naming the function and using brackets around it to contain the information inside of the function when using a function, it goes through the variables inside of it and creates an answer for the problem or solution you have put inside of it. Calling a function means for the user to tell the code to run the function and use this to give a solution or return a value from the function. Also, functions can be used to pass a variable to another function to complete another part of the problem and give a more inadept solution for instance in a loop of an if statement.