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

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

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

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support