Lecture Notes
JAVASCRIPT CONSOLE
➢ What is Console?
The console is an object in JavaScript which is used for
debugging and logging results.
❖ All modern browsers have a web console for
debugging.Console is a global object so it is available in
every scope.
❖ It is also available in the global scope of the browser
window. You can use it as window.console or direct
console.
❖ Here we'll discuss some most used console methods.
➢ Console methods
Console in javascript has several different methods. Among
all the log method is most commonly used: Console.log()
Mainly used to log the output to the console. We can put any
type inside the log(), bet it a string, array, object etc.
Console.table()
It's allows us to generate a table inside a console. Console.count()
It's used to count the number that the function hit by this
counting method.
Console.time()
It's used to track how long does an operation takes to
execute. JAVASCRIPT SCOPE
➢ Scope determines the accessibility (visibility) of
variables, objects and functions.
➢ In JavaScript, a variable has 3 types of scope:
o Block scope
o Function scope
o Global scope
Block Scope
Block scoping means declaring a variable inside the block or
curly brackets {} can not be accessed from outside the
block.
NOTE:
Variables declared with the var keyword can NOT have
block scope. Function scope
❑ Function scoping means variables defined inside a
function are not accessible from outside the function.
❑ Function scope is also known as local scope
NOTE:
Variables declared with var, let and const are quite similar
when declared inside a function.
Global Scope
➢ A variable declared at the top of a program or outside of
a function is considered a global scope variable.
➢ In the program, variable a is a global variable.
➢ If you assign a value to a variable that has not been
declared, it will automatically become a global variable.
➢ This code example will declared a global variable
carName, even if the value is assigned inside a function