Cannot I use functions and call them as mentioned in the code below?

Active3 hr before
Viewed126 times

9 Answers


I am getting the following error message in few lines- "Expected an assignment or function call and instead saw an expression no-unused-expressions". I am new to React js.,Connect and share knowledge within a single location that is structured and easy to search., Can I avoid informal personal interactions at companies that offer free lunch?

What this does is defines 3 handlers for showing the link or hiding, basically toggles on click of button for show/hide.

class Menu extends React.Component {
  constructor(props) {

    this.state = {
      value1: "Link 1",
      showValue1: false,
      value2: "Link 2",
      showValue2: false,
      value3: "Link 3",
      showValue3: false

  click1 = () => {
    this.setState({ showValue1: !this.state.showValue1 });

  click2 = () => {
    this.setState({ showValue2: !this.state.showValue2 });

  click3 = () => {
    this.setState({ showValue3: !this.state.showValue3 });

  render() {
    return (
        <button onClick={() => this.click1()}>Link 1</button>
        {this.state.showValue1 && <h2>{this.state.value1}</h2>}
        <br />
        <button onClick={() => this.click2()}>Link 2</button>
        {this.state.showValue2 && <h2>{this.state.value2}</h2>}
        <br />
        <button onClick={() => this.click3()}>Link 3</button>
        {this.state.showValue3 && <h2>{this.state.value3}</h2>}
        <br />

This process is automatic. Your browser will redirect to your requested content shortly.

 Pretag team - issue, fix, solve, resolve

A function definition is a regular binding where the value of the binding is a function. For example, this code defines square to refer to a function that produces the square of a given number:,For example, this version of power makes its second argument optional. If you don’t provide it or pass the value undefined, it will default to two, and the function will behave like square.,For example, this function—which outputs the ingredients needed to make a batch of hummus—has another function inside it:

 Pretag team - issue, fix, solve, resolve

A function can return a value back into the calling code as the result.,A variable declared inside a function is only visible inside that function.,A function can return a value. If it doesn’t, then its result is undefined.

function showMessage() {
   alert('Hello everyone!');
load more v

When a function is "called" the program "leaves" the current section of code and begins to execute the first line inside the function. Thus the function "flow of control" is: , The program enters the function (starts at the first line in the function code). , It should be noted, that we can utilize (call) other functions inside a function, but we cannot create the recipe for a new function there.

When writing a function, the programmer must provide a blank to plug in what ever data is of current interest; the blank should have a good symbolic name saying what it will represent. Here is a pseudocode function example:

        function average_grade(list_of_grades)
load more v

For example, the following code defines a simple function named square:,For example, consider the following function definition:,Functions must be in scope when they are called, but the function declaration can be hoisted (appear below the call in the code), as in this example:

function square(number) {
   return number * number;
load more v

Here’s a simple example of functional decomposition using two functions. The first function called square simply computes the square of a given number. The second function called sum_of_squares makes use of square to compute the sum of three numbers that have been squared.,Sometimes you can write functions that allow you to solve a specific problem using a more general solution.,Creating a new function can make a program smaller by eliminating repetitive code.

def drawRectangle(t, w, h):
"Get turtle t to draw a rectangle of width w and height h."
for i in range(2):
load more v

Value-returning Function: when only one value returned,Reference parameters useful in three situations:,Return result rather than modify object through reference argument (value-returning function)

Void functions are created and used just like value-returning functions except they do not return a value after the function executes. In lieu of a data type, void functions use the keyword "void." A void function performs a task, and then control returns back to the caller--but, it does not return a value. You may or may not use the return statement, as there is no return value. Even without the return statement, control will return to the caller automatically at the end of the function. A good utilization of a void function would be to print a header/footer to a screen or file.

Remember: there are two kinds of subprograms that the C++ language utilizes: value-returning functions and void functions. Both value-returning functions and void functions receive values through their parameter lists. A value-returning function can only return one value to the calling environment. The caller invokes (calls) a value-returning function by using its name and argument list in an expression (i.e., 1. assignment, 2. output, or as an 3. argument in another function call):

//value-returning function call (assignment):
y = 2.0 * sqrt(x);
//void function call:
//void function call:
load more v

 Example:Below is a simple C/C++ program to demonstrate functions.,The idea is to put some commonly or repeatedly done task together and make a function so that instead of writing the same code again and again for different inputs, we can call the function.,Functions that are executed before and after main() in C

load more v

Other "functions-cannot" queries related to "Cannot I use functions and call them as mentioned in the code below?"