How to check the content and dimensions of variables?

Hi !
I just started using glitch and new to Javascript as well. Now I am reading codes and modifying it. however, I can not know the sizes and the content of variables at any iteration.
Is there a way to know in details what is happening? because I am not facing any errors how ever the final project is not working correctly.

Thanks.

Hey @NoraKG,

You can see what your variable contains by using the statement console.log(VARIABLE_NAME). So, for example, we have this variable that stores some data, like your name.

var name = "NoraKG";

Now if we wanted to see what value the name variable holds, we can use the statement console.log(name). Simply add it to your code like this:

var name = "NoraKG";
console.log(name);

What console.log does, is that it prints the value of name to your browser console, which you can access by pressing Command+Option+J (Mac) or Control+Shift+J (Windows, Linux, Chrome OS). There, you will see the value of name logged.

image

Here’s another example of how console.log can be used.

var name = "NoraKG";
console.log(name);

name = "Someone else";
console.log(name);

In the above code, we’re calling console.log twice after we re-assign the value of name to Something else. Now, if we check the DevTools Console, we’ll see two logs with both of the values logged.

image

The console.log statement is very useful to perform operations on the console as well. Read the full documentation at https://developer.mozilla.org/en-US/docs/Web/API/console.

Hope this helps!

1 Like

if you are talking about string then you can use multiple String operations to check out stuff related to it or do stuff with it.
to check the content you can just console.log(VARIABLE_NAME); and to get a dimensions or more like length of the variable you can do VARAIBLE_NAME.length;

That is exactly what I said above.

Thank you
This is very helpful

1 Like