S
S
Stergy2018-09-12 12:00:41
JavaScript
Stergy, 2018-09-12 12:00:41

How can you display the value of a variable other than console.log?

I'm new to programming, and maybe asking a stupid question, but still.
Dealing with a page written in React, trying to display the value of a variable through console.log
Approximate page structure

export default class extends Component {
функции(){}
функции(){}

render() {

}
}

wherever I write console.log (except for render) - it doesn't work
5b98d55b3762a955491750.bin
When hovering over an error - it says: 'expecting new line or semicolon'
How else can you display the value of a variable?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
cheeck8131, 2018-09-13
@Stergy

The Class construct does not allow inserting simple code into the body, only functions, can you insert console.log() instead of a class method?

class ClassName extends PureComponent{
  constructor(props) {
   super(props)

   this.testMethod = this.testMethod.bind(this);

   console.log('constructor')
  }

  componentDidMount() {
      console.log(123 + 'componentDidMount')

      this.testMethod();
  }

  testMethod() {
      console.log('testMethod')
  }

   render(
     console.log('render до return')
     return <div id='component'>
     {console.log('render')}
     </div>
   )

  // console.log(123); //  вызовет ошибку
}

L
lnked, 2018-09-12
@lnked

write without semicolon (;)
console.log('txt')

A
Alexander Sobolev, 2018-09-12
@san_jorich

Alternatively, you can use localStorage.setItem, .getItem

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question