0% found this document useful (0 votes)
18 views5 pages

Pyramid

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views5 pages

Pyramid

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

console.

log is a function in JavaScript that outputs a


message to the browser's console. It's commonly used
for debugging, displaying values, or verifying program
flow.
Where You See It
 In browsers: You can see the output in the
Developer Tools Console (shortcut: F12 or
Ctrl+Shift+I and go to the Console tab).
 In Node.js: The output will appear in the terminal
or command prompt.
Example
javascript
Copy code
console.log("Hello, World!");
When run, this will print:
Copy code
Hello, World!
Use Cases
1. Debugging: To see variable values or execution
flow.
javascript
Copy code
let x = 10;
console.log("The value of x is:", x); // Outputs: The
value of x is: 10
2. Testing Small Code Snippets:
javascript
Copy code
console.log(2 + 3); // Outputs: 5
3. Displaying Informational Messages:
javascript
Copy code
console.log("Processing complete!");
It's an essential tool for JavaScript developers!

console.log("Let's build a pyramid using JavaScript


basics:");
console.log(" # ");
console.log(" ### ");
console.log(" ##### ");
console.log(" ####### ");
console.log("#########");
One of the most important concepts in programming is
variables. A variable points to a specific memory
address that stores a value. Variables are given a name
which can be used throughout your code to access that
value. Declaring a variable means giving it a name. In
JavaScript, this is often done with the let keyword. For
example, here is how you would declare a hello
variable: Example Code let hello; Variable naming
follows specific rules: names can include letters,
numbers, dollar signs, and underscores, but cannot
contain spaces and must not begin with a number. Use
the let keyword to declare a variable called character.
Note: It is common practice to end statements in
JavaScript with a semicolon. ;

Here's how you can declare a variable called character


using the let keyword in JavaScript:
javascript
Copy code
let character;
Explanation:
1. let: This keyword is used to declare a variable. It
allows you to assign a value to the variable later.
2. Variable Name (character): The variable is named
character.
o It follows the rules:
 Starts with a letter.
 Contains only valid characters (letters,
numbers, $, or _).
 No spaces or special characters.
3. Semicolon (;): It marks the end of the statement.
While not mandatory in JavaScript, it is a good
practice.
At this point, the variable character exists but doesn't
hold any value (it's undefined). You can assign a value
to it later:
javascript
Copy code
character = 'A';
console.log(character); // Outputs: A
let character;
character = 'A'; console.log(character); // Outputs: A

let character;
character = 'A'; console.log(character); // Outputs: A

You might also like