JAVASCRIPT
JavaScript is a versatile programming language primarily used to create dynamic and interactive features on websites.
JavaScript is a scripting language that allows you to implement complex features on web pages.
Browsers have Interpreters. It will converts JAVASCRIPT code to machine code.
Browsers have its own interpreters like
- Chrome β V8-engine
- Edge β Chakra
JavaScript- Identifiers :
var message; β> Variable (Identifier)
message = βJavascriptβ;
func sayHello() {
console.log(βHelloβ)
}
//sayHello Is the identifier for this function.
//variables , objects,functions,arrays ,classes names are identifiers in js.
SCOPE :
In JavaScript, scope refers to the context in which variables and functions are accessible. It determines the visibility and lifetime of these variables and functions within your code. There are three main types of scope in JavaScript.
Global Scope:.
- Variables declared outside any function or block have global scope.
- These variables are accessible from anywhere in the code
example :
let globalVar = "I'm global";
function test() {
console.log(globalVar); // Accessible here
}
test();
console.log(globalVar); // Accessible here too
Function Scope
- Variables declared within a function are local to that function.
- They cannot be accessed from outside the function.
example :
function test() {
let localVar = "I'm local";
console.log(localVar); // Accessible here
}
test();
console.log(localVar); // Error: localVar is not defined
Block Scope:
- Introduced with ES6, variables declared withΒ
let
Β orΒconst
Β within a block (e.g., insideΒ{}
) are only accessible within that block
example :
{
let blockVar = "I'm block-scoped";
console.log(blockVar); // Accessible here
}
console.log(blockVar); // Error: blockVar is not defined
Keywords | Reserved Words
Keywords are reserved words in JavaScript that cannot use to indicate variable labels or function names.
Variables
variables ==> stored values ==> it will stored to ram / It will create separate memory.so we need memory address for access the values.
Stores Anything :
JavaScript will store any value in the variable.
Declaring Variable :
* Var * let * const
we can declare variable using above keywords:
Initialize Variable :
Using assignment operator to assign the value to the variables. var text = "hello";