Variables

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 126:- Variables

In JavaScript, variables are used to store data values. They are like containers that hold values, which can be used later in the program. Variables can be declared using the var, let, or const keyword.

The var keyword was used to declare variables in JavaScript before the release of ES6. It has a function-level scope, which means that it can be accessed within the function it is declared in. If a variable is declared outside of a function using the var keyword, it will be accessible globally.

The let keyword was introduced in ES6 and has a block-level scope, which means that it can be accessed within the block it is declared in. A block is a set of statements enclosed in curly braces {}. Variables declared with let can be updated but not redeclared.

The const keyword is used to declare variables whose values are constant and cannot be changed. Like let, const has a block-level scope. Once a value is assigned to a variable using the const keyword, it cannot be reassigned.

Here's an example of declaring a variable using var, let, and const:

javascriptCopy code

// using var var x = 5; function myFunction() {  var y = 10;  console.log(x + y); // output: 15 } console.log(x); // output: 5 console.log(y); // output: Uncaught ReferenceError: y is not defined // using let let a = 15; if (true) {  let b = 10;  console.log(a + b); // output: 25 } console.log(a); // output: 15 console.log(b); // output: Uncaught ReferenceError: b is not defined // using const const PI = 3.14; console.log(PI); // output: 3.14 PI = 3.14159; // output: Uncaught TypeError: Assignment to constant variable.

15. Starting with JavaScript

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

I am not able to access videos from second class and further. I have already completed first class

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?