Concatenation with Comma and Plus Sign

Asked

Viewed 176 times

0

I am studying nodejs, and doing some tests with some native modules of Node I came across the following instruction.

For free memory printing on computer:

const os = require('os');

console.log('Memoria Livre: ', os.freemem());

This comma separating the string from the constant is concatenative, correct?

If yes, what is the difference between comma and/or +

console.log('Memoria Livre: ', os.freemem());

and/or

console.log('Memoria Livre: ' + os.freemem());

There are other means of concatenation in js?

  • 1

    you can also use += which sum the variable + itself plus the other value

1 answer

3


This is not concatenation, the function log(...) is multiple arguments.

When you do console.log('Memoria Livre: ' + os.freemem()); you are calling the function with 1 argument, which is a string 'Memoria Livre: ' + os.freemem() already in console.log('Memoria Livre: ', os.freemem()); you are passing 2 arguments to the function log(...).

That’s not from the Ode.

console.log(obj1 [, obj2, ..., objN]);

console.log(msg [, subst1, ..., substN]);

console.log('a', 'b', 'c');
console.log('a'+'b'+'c');

let teste = {
  a: 'a',
  b: 'b'
}

console.log('a'+teste);

console.log('a', teste);

  • True, now that I’ve paid attention. Thank you. Cool brizei now rs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.